Repository navigation
Converter map validation: check every axis, also after an empty one - #87
Merged
Merged
Conversation
check_group_reads_v5 stopped checking a tensor's axes at the first axis with an effective length of 0, so a later axis never reached the overflow checks and a map with a huge stride after an empty axis loaded (and Decoder::indexed could then overflow in signed 64-bit). The loop now continues past an empty axis: it still means the tensor reads nothing, but every axis gets its checked multiplication and addition. Fixes #54 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
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.
Fixes #54
What was wrong
check_group_reads_v5(clean/converter/src/map.cpp) stopped checking a tensor's axes as soon as one axis had an effective length of 0 (limit: 0). The axes after it never reached thechecked_mul/checked_addoverflow checks, so a map with, for example, axes[{stride: 1, limit: 0}, {stride: 9223372036854775807}]loaded, andDecoder::indexed(clean/converter/src/convert5.cpp) would then computestride * indexin signed 64-bit and overflow.There is no visible effect today: the zero-limit axis already makes the tensor all zeros and every source read stays bounds-checked, and it needs a hand-made map. But the map is meant to be validated completely before any input is read, and this was a gap in that.
The fix
The loop over the tensor's axes no longer breaks at an empty axis; it records that the tensor reads nothing (
any = false) and continues, so every non-empty axis goes through the checked multiplication and addition. An empty axis still adds no span, and a tensor that reads nothing still skips the source-range check afterwards, as before. No other change.The test
A new mutation in
corrupt_map_cases(clean/converter/tests/run_tests5.py, next to the existing ones): on the tensorG1/bof the synthetic feature map, axis 0 getslimit: 0and axis 1 getsstride: 9223372036854775807. It must be refused as a damaged map (exit code 20, "converter data is damaged") before any DLL is opened, like every other mutation of that table.Before / after (MSVC, Release;
cmake -S clean/converter -B <out> -G Ninja ...,cmake --build <out>,ctest --test-dir <out> -R synthetic5):1069 checks passed, 3 failed(exit code 10 "This file cannot be read": the map loaded and the converter went on to read the missing DLL; "message" and "no DLL read" fail too).1072 checks passed, 0 failed.Tested
ctestof the converter:unit,decompression-vectors,synthetic,synthetic5: all passed with the fix.synthetic5before the fix (with the new mutation) fails as above.Not tested
run_tests5.pyhere (their stand-ins are not in the repository), as in CI.Decoder::indexeditself is unchanged and was not exercised with an overflowing map (the map is now refused before it).