Validate SpaceDepth shape arithmetic - #32039
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Review — PR #32039: Validate SpaceDepth shape arithmetic Bug analysis — what was actually broken pre-PR Two related issues in onnxruntime/core/providers/cpu/tensor/space_depth_ops.h's
The negative- The fix — three components
Pragma removal is the natural consequence: with the actual UB sources eliminated, MSVC has nothing to warn about. Small correctness point on the guards For SpaceToDepth: if (input_depth > int64_max / blocksize || input_depth * blocksize > int64_max / blocksize) {
return INVALID_ARGUMENT("SpaceToDepth output depth exceeds int64_t limits");
}
output_depth = input_depth * blocksize * blocksize;I walked the algebra: this correctly guards For DepthToSpace: if (input_height > int64_max / blocksize || input_width > int64_max / blocksize) {
return INVALID_ARGUMENT("DepthToSpace output dimensions exceed int64_t limits");
}
output_height = input_height * blocksize;
output_width = input_width * blocksize;Straightforward, correct. Style nits (all minor)
Test coverage — where it lands, and where it doesn't Test #1 Test #2
So Test #2 actually covers the divisibility rewrite, not the overflow guards. That's still valuable — the rewrite is the piece that actually removes the pre-PR UB (integer overflow on Actual overflow guards are not exercised by any test. To hit them you'd need an Two reasonable ways to close this coverage gap — pick one:
Not blocking, but worth choosing consciously. One additional gap — CRD vs DCR mode
Broader observation (for follow-up, not this PR) The CI 1/1 check OK on Recommendation Approve pending:
Nice to have (fast follow-up, not blocking):
The core change is small, precise, and eliminates real UB rather than papering over it with a warning suppression. Divisibility rewrite is correct-and-safe. Overflow guards are the standard idiom applied correctly. Test #1 is on the money. |
Description
Validates
blocksizeand uses overflow-safe shape arithmetic shared bySpaceToDepthandDepthToSpace. Removes the obsolete warning suppression and adds boundary tests.Motivation and Context
Invalid or extreme block sizes could cause divide-by-zero or signed overflow during output-shape calculation.