[tests] Fix crash in BitmapContextTest.CreateAdaptive_2 by computing correct buffer size.#24862
Conversation
…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>
There was a problem hiding this comment.
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 * Heightcomputed fromCGBitmapParameters. - 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.
| var renderingBufferProviderSize = checked(parameters.AlignedBytesPerRow * parameters.Height); | ||
| var renderingBufferProvider = CGRenderingBufferProvider.Create (IntPtr.Zero, renderingBufferProviderSize, | ||
| lockPointer: (info) => { |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #ef7318f] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #ef7318f] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #ef7318f] Build passed (Build macOS tests) ✅Pipeline on Agent |
🚀 [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 macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
…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>
…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>
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.