Fix/winml image dimension overflow - #32046
Merged
Akshay Sonawane (apsonawane) merged 2 commits intoAug 13, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 22:17
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 22:19
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens WinML image-tensor handling against invalid or overflow-prone dimensions by adding stronger validation in the WinML ↔ ORT descriptor conversion path and in the D3D12 upload path, plus new test coverage to ensure oversized image dimensions are rejected.
Changes:
- Added explicit
E_INVALIDARGvalidation for IMAGE denotation tensors to require positiveH/Wand<= INT32_MAX. - Made GPU upload size computation overflow-safe (64-bit arithmetic + checked math) and added output-resource bounds checks.
- Extended WinML test utilities to generate image-denoted inputs and added a new API test for rejecting oversized image dimensions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| winml/test/common/protobufHelpers.h | Extends CreateModel helper signature to support an image_input flag. |
| winml/test/common/protobufHelpers.cpp | Sets ONNX TypeProto denotation to "IMAGE" for test model inputs when requested. |
| winml/test/api/LearningModelAPITest.h | Registers the new RejectOversizedImageDimensions test. |
| winml/test/api/LearningModelAPITest.cpp | Adds the oversized image dimension rejection test and required <limits> include. |
| winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp | Validates IMAGE tensor H/W are positive and <= INT32_MAX before creating ImageFeatureDescriptor. |
| winml/lib/Api.Image/VideoFrameToTensorConverter.cpp | Uses 64-bit checked arithmetic for buffer sizing, validates positive dims, checks resource bounds, and avoids offset/size overflow in copy/unmap. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/winml-image-dimension-overflow
branch
August 13, 2026 20:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request strengthens validation for image tensor dimensions and improves robustness in both the core library and test code. The main focus is to ensure that image tensor height and width are always positive and do not exceed the maximum allowed integer size, preventing potential overflows or invalid memory access. It also updates related tests and utility functions to cover these cases.
Validation Improvements:
CreateImageFeatureDescriptorto ensure image tensor height and width are positive and no greater thanINT32_MAX, throwingE_INVALIDARGif not (winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp).ConvertSoftwareBitmapToGPUTensor, changed buffer size calculations to useUINT64, added validation for positive tensor dimensions, and ensured the upload size does not exceedSIZE_Tlimits. Also, verified output resource bounds and used safe arithmetic functions to prevent overflows (winml/lib/Api.Image/VideoFrameToTensorConverter.cpp). [1] [2] [3]Test Enhancements:
RejectOversizedImageDimensions, to verify that models with image dimensions exceedingINT32_MAXare correctly rejected (winml/test/api/LearningModelAPITest.cpp,LearningModelAPITest.h). [1] [2] [3] [4]CreateModelutility to support animage_inputflag, allowing creation of image-typed model inputs for testing validation logic (winml/test/common/protobufHelpers.cpp,protobufHelpers.h). [1] [2] [3]General Code Quality:
<limits>where needed to support the new validation checks and ensure portability and correctness. [1] [2] [3]These changes help prevent invalid image tensor shapes from being processed, improving the reliability and safety of the codebase.