Fall back to object encoding for out-of-range BJData ndarray elements - #5438
Open
22elix3r wants to merge 1 commit into
Open
Fall back to object encoding for out-of-range BJData ndarray elements#543822elix3r wants to merge 1 commit into
22elix3r wants to merge 1 commit into
Conversation
write_bjdata_ndarray only checked that _ArrayData_ elements were the right number kind, then static_cast-truncated values that did not fit the named type (256 as uint8 became 0). Range-check each element and encode as a plain object when it does not fit. Signed-off-by: elix3r <157088510+22elix3r@users.noreply.github.com>
5 tasks
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated and/or formatted correctly. 📎 A ready-to-apply patch is attached to the failed workflow run as the git apply amalgamation.patchThis does not require installing astyle yourself. |
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.
Summary
to_bjdata()validated that ndarray_ArrayData_elements were the right number kind (integer vs float) but not that they fit the named_ArrayType_. An element such as256with_ArrayType_ = \"uint8\"wasstatic_cast-truncated to0and round-tripped as a different value with no error.Related Issue
Fixes #5403
Changes Made
_ArrayData_element against the BJData wire type (uint8/int8/uint16/…/char/byte) before writing_ArraySize_)bjdata.mdTesting
Commands executed:
python3 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s .cmake -S . -B build -DJSON_BuildTests=ON -DCMAKE_BUILD_TYPE=Debug -DJSON_FastTests=ONcmake --build build --target test-bjdata_cpp11./build/tests/test-bjdata_cpp11 --no-skip -tc='*5403*'./build/tests/test-bjdata_cpp11 --no-skip -tc=BJData -sc='parsing values,array,*out-of-range*,*not matching*'Results:
Notes
In-range extrema (
0/255for uint8,-128/127for int8, …) still encode as packed ndarrays. Floating-point types are unchanged (IEEE truncation ofdoubletosingleis expected).make amalgamate.