Skip to content

fix: resolve CodeQL integer-overflow and obsolete warnings#89

Merged
devin-ai-integration[bot] merged 1 commit into
feature/devin-20260712-sonar-qualityfrom
feature/devin-20260712-sonar-codeql
Jul 12, 2026
Merged

fix: resolve CodeQL integer-overflow and obsolete warnings#89
devin-ai-integration[bot] merged 1 commit into
feature/devin-20260712-sonar-qualityfrom
feature/devin-20260712-sonar-codeql

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you lint your code locally prior to submission?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Summary

Resolves the CodeQL alerts introduced in the SonarCloud cleanup branch:

  • ArtQRCode.cs: avoids integer overflow in background-image and module coordinate calculations by promoting multiplications to float (pixelsPerModuleF) before casting to SKRect/DrawBitmap coordinates.
  • QRCode.cs: avoids overflow in DrawIcon width/height and border-radius calculations by casting operands to float before multiplication.
  • SvgQRCode.cs: guards ImageAttributes? in IsBlockedByLogo with HasValue.
  • Tests: replaces obsolete GetGraphic overloads with their non-obsolete *GraphicOptions equivalents and corrects the legacy BezahlCode pragma from CS0612 to CS0618.

Verification:

  • dotnet build QRCoder.Core.sln --configuration Release 0 warnings / 0 errors
  • dotnet test QRCoder.Core.Tests/ -f net10.0 --configuration Release 502 passed

This is a follow-up phase PR targeting the integration branch feature/devin-20260712-sonar-quality.

Link to Devin session: https://app.devin.ai/sessions/20c92a1bad724f63b8be89a9e195e664
Requested by: @afonsoft


Open in Devin Review

- Cast SKRect/DrawBitmap multiplications to float before evaluation to avoid int overflow.

- Guard nullable ImageAttributes in SvgQRCode.IsBlockedByLogo.

- Update renderer tests to use non-obsolete options overloads.

- Correct PayloadGeneratorTests pragma (CS0612 -> CS0618).

Co-Authored-By: Afonso Dutra Nogueira Filho <afonsoft@gmail.com>
@afonsoft afonsoft self-assigned this Jul 12, 2026
@afonsoft
afonsoft self-requested a review July 12, 2026 18:23
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@sonarqubecloud

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Open in Devin Review

Comment on lines +219 to +223
float iconDestWidth = iconSizePercent * (float)bmp.Width / 100f;
float iconDestHeight = iconDestWidth * (float)icon.Height / (float)icon.Width;
float iconX = ((float)bmp.Width - iconDestWidth) / 2;
float iconY = ((float)bmp.Height - iconDestHeight) / 2;
var centerDest = new SKRect(iconX - iconBorderWidth, iconY - iconBorderWidth, iconX - iconBorderWidth + iconDestWidth + iconBorderWidth * 2f, iconY - iconBorderWidth + iconDestHeight + iconBorderWidth * 2f);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Integer overflow risk fixed in icon size calculation

The old code at QRCoder.Core/Renderers/QRCode.cs:219 computed iconSizePercent * bmp.Width as int * int, which could overflow for large bitmaps (e.g., iconSizePercent=15 and bmp.Width > 143M pixels). The new code casts bmp.Width to float first, avoiding the overflow. While the overflow scenario is unlikely in practice (QR bitmaps are small), the fix is correct and makes the arithmetic more robust. The same pattern is applied to iconDestHeight, iconX, iconY, and centerDest calculations.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +229 to +230
if (!attr.HasValue)
return false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: SvgQRCode null check is defensive — callers already guard against null attr

The new null check if (!attr.HasValue) return false at QRCoder.Core/Renderers/SvgQRCode.cs:229 is purely defensive. Both call sites (lines 143 and 195) use short-circuit evaluation: logo == null || !logo.FillLogoBackground() || !IsBlockedByLogo(...). Since logoAttr is only set when logo != null (line 129-130), and IsBlockedByLogo is only reached when logo != null and logo.FillLogoBackground() is true, attr will always have a value when the method executes. The check prevents a potential InvalidOperationException if the method were ever called directly with a null attr in the future.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +1211 to +1213
#pragma warning disable CS0618
var generator = new PayloadGenerator.BezahlCode(AuthorityType.singlepayment, name, account: account, bnc: bnc, amount: amount);
#pragma warning restore CS0612
#pragma warning restore CS0618

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Pragma change from CS0612 to CS0618 is correct for Obsolete attributes with messages

The [Obsolete("message")] form on the AuthorityType enum values (e.g., singlepayment, singledirectdebit, periodicsinglepayment at QRCoder.Core/Generators/PayloadGenerator.cs:2841-2865) generates compiler warning CS0618 (not CS0612). CS0612 is for [Obsolete] without a message string. The old pragmas were suppressing the wrong warning, meaning the actual CS0618 warnings were likely still being emitted. This fix ensures the correct warning is suppressed.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

{
var bgOffset = 4 - offset;
using (var resizedImage = Resize(backgroundImage, size - (2 * bgOffset * pixelsPerModule)))
var dataAreaSize = size - (int)(2f * bgOffset * pixelsPerModule);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: ArtQRCode dataAreaSize calculation changes from pure int to float-then-int-cast

The old expression size - (2 * bgOffset * pixelsPerModule) was pure integer arithmetic. The new expression size - (int)(2f * bgOffset * pixelsPerModule) computes via float then truncates back to int. For the values involved (bgOffset is either 0 or 4, pixelsPerModule is a small positive int), the results are identical since 2 * bgOffset * pixelsPerModule is always an exact integer representable in float. The change is consistent with the broader pattern of using float arithmetic throughout the renderer, but the intermediate float conversion is unnecessary for these specific values.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration
devin-ai-integration Bot merged commit f6308b3 into feature/devin-20260712-sonar-quality Jul 12, 2026
14 checks passed
@afonsoft
afonsoft deleted the feature/devin-20260712-sonar-codeql branch July 13, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant