Skip to content

[tests] Fix BitmapContextTest.CreateAdaptive_3/_4 crash due to undersized buffer#24920

Merged
rolfbjarne merged 2 commits intomainfrom
dev/rolf/tests-create-adaptive-crash
Mar 18, 2026
Merged

[tests] Fix BitmapContextTest.CreateAdaptive_3/_4 crash due to undersized buffer#24920
rolfbjarne merged 2 commits intomainfrom
dev/rolf/tests-create-adaptive-crash

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

CreateAdaptive_3 and CreateAdaptive_4 used a hardcoded 512-byte buffer for
a 256x256 adaptive bitmap context. When ToImage() called
CGBitmapContextCreateImage, CoreGraphics tried to copy the bitmap data from
this tiny buffer, reading past the allocation and causing a SIGSEGV.

Fix CreateAdaptive_3 by computing the buffer size from
parameters.AlignedBytesPerRow * parameters.Height (matching CreateAdaptive_2).

Fix CreateAdaptive_4 by using a 1MB buffer, large enough for any 256x256
adaptive bitmap format.

…ized buffer

CreateAdaptive_3 and CreateAdaptive_4 used a hardcoded 512-byte buffer for
a 256x256 adaptive bitmap context. When ToImage() called
CGBitmapContextCreateImage, CoreGraphics tried to copy the bitmap data from
this tiny buffer, reading past the allocation and causing a SIGSEGV.

Fix CreateAdaptive_3 by computing the buffer size from
parameters.AlignedBytesPerRow * parameters.Height (matching CreateAdaptive_2).

Fix CreateAdaptive_4 by using a 1MB buffer, large enough for any 256x256
adaptive bitmap format.

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 CoreGraphics adaptive bitmap context tests caused by providing an undersized rendering buffer to CGBitmapContext and then calling ToImage() (which triggers CGBitmapContextCreateImage to read the full backing store).

Changes:

  • CreateAdaptive_3: compute the buffer size from parameters.AlignedBytesPerRow * parameters.Height (matching the existing CreateAdaptive_2 pattern).
  • CreateAdaptive_4: increase the preallocated buffer from 512 bytes to 1MB to avoid out-of-bounds reads during image creation.

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

Comment thread tests/monotouch-test/CoreGraphics/BitmapContextTest.cs Outdated
…coding

Address review feedback: replace the hardcoded 1MB buffer with a properly
computed size from parameters.AlignedBytesPerRow * parameters.Height in
OnAllocate, matching the pattern used in CreateAdaptive_2 and _3.

The buffer provider is now created inside OnAllocate and stored in an
outer-scope variable so it can be explicitly disposed afterward to verify
the releaseInfo callback is called.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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 18, 2026 15:40
@vs-mobiletools-engineering-service2

This comment has been minimized.

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

✅ [CI Build #0511a9d] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 0511a9d5b7278be792c02849cf13bc745410d8dd [PR build]

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

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

Pipeline on Agent
Hash: 0511a9d5b7278be792c02849cf13bc745410d8dd [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: 0511a9d5b7278be792c02849cf13bc745410d8dd [PR build]

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

✅ [CI Build #0511a9d] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 0511a9d5b7278be792c02849cf13bc745410d8dd [PR build]

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

🚀 [CI Build #0511a9d] 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: 0511a9d5b7278be792c02849cf13bc745410d8dd [PR build]

@rolfbjarne rolfbjarne merged commit 4077c4b into main Mar 18, 2026
48 checks passed
rolfbjarne added a commit that referenced this pull request Mar 20, 2026
…ized buffer (#24920)

CreateAdaptive_3 and CreateAdaptive_4 used a hardcoded 512-byte buffer for
a 256x256 adaptive bitmap context. When ToImage() called
CGBitmapContextCreateImage, CoreGraphics tried to copy the bitmap data from
this tiny buffer, reading past the allocation and causing a SIGSEGV.

Fix CreateAdaptive_3 by computing the buffer size from
parameters.AlignedBytesPerRow * parameters.Height (matching CreateAdaptive_2).

Fix CreateAdaptive_4 by using a 1MB buffer, large enough for any 256x256
adaptive bitmap format.

---------

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

CreateAdaptive_3 and CreateAdaptive_4 used a hardcoded 512-byte buffer for
a 256x256 adaptive bitmap context. When ToImage() called
CGBitmapContextCreateImage, CoreGraphics tried to copy the bitmap data from
this tiny buffer, reading past the allocation and causing a SIGSEGV.

Fix CreateAdaptive_3 by computing the buffer size from
parameters.AlignedBytesPerRow * parameters.Height (matching CreateAdaptive_2).

Fix CreateAdaptive_4 by using a 1MB buffer, large enough for any 256x256
adaptive bitmap format.

---------

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