Repository navigation
sas_rle: null-check the output buffer before pointer arithmetic - #438
Merged
Merged
Conversation
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.
sas_rle_compressruns a measuring pass with a NULL output buffer (throughsas_rle_compressed_len, and the sas7bdat writer'sctx->compress(NULL, 0, ...)) to size a compressed row before allocating. Its two emit helpers,sas_rle_copy_runandsas_rle_insert_run, evaluateoutput_buf + offsetbefore theif (output_buf == NULL)early return. Once an earlier run has advanced the offset, the measuring pass formsNULL + offsetwith a non-zero offset, which is undefined behavior under C11 6.5.6p8. Nothing dereferences the pointer, but UBSan's pointer-overflow check flags it, and it fires in the project's ownmake check(the sas7bdat row-compressed round-trips) once the suite is built with-fsanitize=undefined.Move the NULL check above the pointer arithmetic in both helpers so the offset is only applied to a real buffer. The writing pass is unaffected and the measuring pass returns the same length as before.
Built with
-fsanitize=undefined,sas_rle_compressed_len("abcdef\0\0\0\0\0\0\0\0\0\0", 16)reportsruntime error: applying non-zero offset 7 to null pointeratreadstat_sas_rle.c:194before the change and returns 8 cleanly after.