Skip to content

Fix/winml image dimension overflow - #32046

Merged
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/winml-image-dimension-overflow
Aug 13, 2026
Merged

Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/winml-image-dimension-overflow

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

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:

  • Added explicit checks in CreateImageFeatureDescriptor to ensure image tensor height and width are positive and no greater than INT32_MAX, throwing E_INVALIDARG if not (winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp).
  • In ConvertSoftwareBitmapToGPUTensor, changed buffer size calculations to use UINT64, added validation for positive tensor dimensions, and ensured the upload size does not exceed SIZE_T limits. Also, verified output resource bounds and used safe arithmetic functions to prevent overflows (winml/lib/Api.Image/VideoFrameToTensorConverter.cpp). [1] [2] [3]

Test Enhancements:

  • Added a new test, RejectOversizedImageDimensions, to verify that models with image dimensions exceeding INT32_MAX are correctly rejected (winml/test/api/LearningModelAPITest.cpp, LearningModelAPITest.h). [1] [2] [3] [4]
  • Updated the CreateModel utility to support an image_input flag, allowing creation of image-typed model inputs for testing validation logic (winml/test/common/protobufHelpers.cpp, protobufHelpers.h). [1] [2] [3]

General Code Quality:

  • Included <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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_INVALIDARG validation for IMAGE denotation tensors to require positive H/W and <= 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.

Comment thread winml/lib/Api.Image/VideoFrameToTensorConverter.cpp
Comment thread winml/test/api/LearningModelAPITest.cpp
@apsonawane
Akshay Sonawane (apsonawane) merged commit c14118f into main Aug 13, 2026
96 of 99 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/winml-image-dimension-overflow branch August 13, 2026 20:39
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.

3 participants