Skip to content

[tests] Fix crash in BitmapContextTest.CreateAdaptive_2 by computing correct buffer size.#24862

Merged
rolfbjarne merged 2 commits intomainfrom
dev/rolf/bitmap-context-crash-fix-seventeenth-attempt
Mar 10, 2026
Merged

[tests] Fix crash in BitmapContextTest.CreateAdaptive_2 by computing correct buffer size.#24862
rolfbjarne merged 2 commits intomainfrom
dev/rolf/bitmap-context-crash-fix-seventeenth-attempt

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

The hardcoded 512-byte rendering buffer was far too small for a 256x256
adaptive bitmap context. Replace with the correct size computed from the
adaptive parameters (AlignedBytesPerRow * Height) to avoid SIGSEGV in
CGBitmapContextCreateImage when it tries to read beyond the buffer.

…correct buffer size.

The hardcoded 512-byte rendering buffer was far too small for a 256x256
adaptive bitmap context. Replace with the correct size computed from the
adaptive parameters (AlignedBytesPerRow * Height) to avoid SIGSEGV in
CGBitmapContextCreateImage when it tries to read beyond the buffer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in the CoreGraphics adaptive bitmap context test by allocating a rendering buffer sized according to the adaptive bitmap parameters, preventing CoreGraphics from reading past the provided buffer when creating an image.

Changes:

  • Replace a hardcoded 512-byte rendering buffer with AlignedBytesPerRow * Height computed from CGBitmapParameters.
  • Use checked arithmetic/casts when computing and allocating the buffer size to avoid silent overflows.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +152 to 154
var renderingBufferProviderSize = checked(parameters.AlignedBytesPerRow * parameters.Height);
var renderingBufferProvider = CGRenderingBufferProvider.Create (IntPtr.Zero, renderingBufferProviderSize,
lockPointer: (info) => {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

CGRenderingBufferProvider.Create returns a nullable provider; if it returns null here, the native trampoline will hit a NullReferenceException (or worse) when trying to retain the handle. Consider asserting/throwing when the provider is null (as is done in CreateAdaptive_4) so the test fails with a clear message.

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne enabled auto-merge (squash) March 10, 2026 12:46
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #ef7318f] Build passed (Build packages) ✅

Pipeline on Agent
Hash: ef7318f82b2c6ebbe69918aa0d0a3a0fd3ef8f92 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #ef7318f] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: ef7318f82b2c6ebbe69918aa0d0a3a0fd3ef8f92 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: ef7318f82b2c6ebbe69918aa0d0a3a0fd3ef8f92 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #ef7318f] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: ef7318f82b2c6ebbe69918aa0d0a3a0fd3ef8f92 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #ef7318f] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: ef7318f82b2c6ebbe69918aa0d0a3a0fd3ef8f92 [PR build]

@rolfbjarne rolfbjarne merged commit bde31c1 into main Mar 10, 2026
48 checks passed
rolfbjarne added a commit that referenced this pull request Mar 20, 2026
…correct buffer size. (#24862)

The hardcoded 512-byte rendering buffer was far too small for a 256x256
adaptive bitmap context. Replace with the correct size computed from the
adaptive parameters (AlignedBytesPerRow * Height) to avoid SIGSEGV in
CGBitmapContextCreateImage when it tries to read beyond the buffer.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rolfbjarne added a commit that referenced this pull request Mar 20, 2026
…correct buffer size. (#24862)

The hardcoded 512-byte rendering buffer was far too small for a 256x256
adaptive bitmap context. Replace with the correct size computed from the
adaptive parameters (AlignedBytesPerRow * Height) to avoid SIGSEGV in
CGBitmapContextCreateImage when it tries to read beyond the buffer.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants