Repository navigation
Conversation
EncodeSymbols() could not encode a symbol at or above 2^31, and wrote
out of bounds trying. Symbols are zig-zagged prediction residuals, so a
residual of magnitude 2^30 or more produces one. A mesh whose
coordinates span more than a float can express reaches it from
draco_encoder directly:
v -3.4028235e38 0 0
v 3.4028235e38 1 0
v 0 0 1
f 1 2 3
draco_encoder -i wide.obj -o wide.drc -qp 14 # access violation
Two places fail, one after the other.
ApproximateRawSchemeBits() is called for every input to price the raw
scheme, and passes |max_value| to ComputeShannonEntropy() as an int,
which sizes its frequency table as |max_value| + 1. For UINT32_MAX that
is zero entries, and the counting loop writes past it. The raw scheme
cannot hold values longer than kMaxRawEncodingBitLength bits and is
never chosen for them, so the estimate is now computed only when it is a
candidate (or is requested explicitly).
EncodeTaggedSymbols() counts bit lengths in TaggedBitLengthFrequencies,
which has kMaxTagSymbolBitLength (32) entries, but a value at or above
2^31 is 32 bits long and indexes entry 32. The table now has one entry
more, and the tag encoder is told so. RAnsSymbolEncoder::Create() drops
trailing zero frequencies, so the stream is unchanged until such a value
occurs, and the decoder already reads a 32-bit tag.
Output is byte-identical to before for every other input: draco_encoder
on bun_zipper.ply, cube_att.obj, test_nm.obj, sphere.obj and a point
cloud at -cl 0, 4, 7 and 10 writes the same bytes with and without this
change.
TestLargestSymbolValues round-trips {0xffffffff, 0x80000000, 7, 0}
through EncodeSymbols() and DecodeSymbols(). Before this change it
crashes.
This branch has not been deployed
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.
EncodeSymbols() could not encode a symbol at or above 2^31, and wrote out of bounds trying. Symbols are zig-zagged prediction residuals, so a residual of magnitude 2^30 or more produces one. A mesh whose coordinates span more than a float can express reaches it from draco_encoder directly:
Two places fail, one after the other.
ApproximateRawSchemeBits() is called for every input to price the raw scheme, and passes |max_value| to ComputeShannonEntropy() as an int, which sizes its frequency table as |max_value| + 1. For UINT32_MAX that is zero entries, and the counting loop writes past it. The raw scheme cannot hold values longer than kMaxRawEncodingBitLength bits and is never chosen for them, so the estimate is now computed only when it is a candidate (or is requested explicitly).
EncodeTaggedSymbols() counts bit lengths in TaggedBitLengthFrequencies, which has kMaxTagSymbolBitLength (32) entries, but a value at or above 2^31 is 32 bits long and indexes entry 32. The table now has one entry more, and the tag encoder is told so. RAnsSymbolEncoder::Create() drops trailing zero frequencies, so the stream is unchanged until such a value occurs, and the decoder already reads a 32-bit tag.
Output is byte-identical to before for every other input: draco_encoder on bun_zipper.ply, cube_att.obj, test_nm.obj, sphere.obj and a point cloud at -cl 0, 4, 7 and 10 writes the same bytes with and without this change.
TestLargestSymbolValues round-trips {0xffffffff, 0x80000000, 7, 0} through EncodeSymbols() and DecodeSymbols(). Before this change it crashes.