Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:24:15+00:00 2026-06-04T15:24:15+00:00

I’ve just run code analysis on a project I’m working on and I’ve been

  • 0

I’ve just run code analysis on a project I’m working on and I’ve been alerted to this message.

Warning 17 CA2122 : Microsoft.Security : ‘Quantizer.Quantize(Image)’
calls into ‘Bitmap.LockBits(Rectangle, ImageLockMode, PixelFormat)’
which has a LinkDemand. By making this call,
‘Bitmap.LockBits(Rectangle, ImageLockMode, PixelFormat)’ is indirectly
exposed to user code. Review the following call stack that might
expose a way to circumvent security protection:
->’Quantizer.Quantize(Image)’ ->’Quantizer.Quantize(Image)’ ->’ImageFactory.SaveFileAndReset(string)’ ->’ImageFactory.Save(string)’

    private void SaveFileAndReset(string path)
    {
        // Fix the colour palette of gif images.
        if (this.imageFormat == ImageFormat.Gif)
        {
            OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
            this.Image = quantizer.Quantize(this.Image);
        }

        /// etc....

The information I could find on MSDN was very brief and I couldn’t extract anything particularly meaningful from it and most answers I have found online simply suggest turning of the warning with a flag obviously this is something I do not want to do without being absolutely sure that I am safe to do so.

Could someone please explain what this actually means and how I would go about fixing any security issues I have that are triggering the warning?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:24:16+00:00Added an answer on June 4, 2026 at 3:24 pm

    It looks like you have probably encountered a false positive in the rule, which does not appear to properly account for default security transparency settings under .NET 4.0. To avoid the problem, you could simply make the default transparency explicit by adding the following two assembly-level attributes to the assembly that contains ImageFactory and OctreeQuantizer:

    [assembly: SecurityCritical]
    [assembly: SecurityRules(SecurityRuleSet.Level2)]
    

    Since these match the CLR 4.0 defaults, adding the attributes will not affect the runtime behaviour of your code. However, the presence of the attributes will allow the CA2122 rule to recognize that the problem that it is intended to detect is not actually present in your code.

    If you are interested in learning more about the transparency model and the security rule levels, see http://blogs.msdn.com/b/shawnfa/archive/2009/11/03/transparency-101-basic-transparency-rules.aspx, http://blogs.msdn.com/b/shawnfa/archive/2009/11/09/transparency-as-enforcement-in-clr-v4.aspx, and http://blogs.msdn.com/b/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.