Repository navigation
Fix undefined behavior in the OASIS real and integer encoding - #2509
Closed
nikosavola wants to merge 2 commits into
Closed
nikosavola wants to merge 2 commits into
nikosavola wants to merge 2 commits into
Conversation
- the minimum int64 is written as -0 on master, so that test fails until the fix
- reals are copied with `memcpy` instead of read through a union, one `write_real` template serves float and double - the minimum int64 is now an error, negating it was undefined and wrote -0 - the point list reservation is capped, since the point count comes from the file
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.
The OASIS reader and writer read the bits of a float or double through a union. That is undefined behavior in C++, so they now use
memcpy. The writer also had two copies of the real encoding, one for float and one for double. They are now one template.The writer negated a negative int64 before writing it. For the minimum value$-2^{63}$ this is undefined, and in practice it wrote $-0$ . OASIS cannot store this value, so the writer now reports an error for it.
The reader reserved space for the point count given in the file. A broken file could ask for a huge amount of memory this way. The reservation is now capped at$2^{16}$ points, and the list grows as usual after that.
The new tests write integer and real values at the edges of their ranges and read them back. The test for the minimum int64 fails on master.