fix: Deprecate SIMD version of SkipWhitespace to prevent BOF #2213
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.
Hi all,
I'm Junwha Hong, from the research group S2Lab in UNIST, we found a buffer-overflow from rapidjson by our custom tool, and patched it.
the detailed information is as follows.
Summary
Problem Statement
The buffer overflow arises when the reader utilizes RAPIDJSON_SIMD and a filestream which has no specification of length or end.
SkipWhitespace_SIMD(const char* p) checks whether all the char characters of 16-bytes matches the whitespaces characters. thus, it will escape the for loop if there is a null string inside a 16-bytes batch.
The problem occurs here, because null string is not always placed at the end of the 16-bytes. thus, if the null string is placed at the 16-bytes aligned address, there will be loads of 15 invalid bytes.
Patch
The SkipWhitespace_SIMD(const char* p, const char* end) checks sanity safely by
for (; p <= end - 16; p += 16)
. thus we need to deprecate the SIMD feature for the simple StringStream and InsituStringStream which have no end specification.Callstack at BOF
Thank you.