Repository navigation
Conversation
M4() packs four 1-byte opcodes into a 32-bit integer by shifting op4 left by 24 bits. When op4 >= 128 (such as OP_neq in the typeof optimization), shifting a signed int left by 24 overflows the sign bit and triggers undefined behavior in C11/C17 (6.5.7p4), caught by UBSan's shift-base check when built without -fwrapv. Perform the packing shifts in uint32_t and cast the result to int to match va_arg(ap, int) in code_match(). Unpack via uint32_t in code_match() to avoid implementation-defined signed right shifts on negative values.
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.
M4()packs four 1-byte opcodes into a 32-bit integer by shiftingop4left by 24 bits. Whenop4 >= 128(such asOP_neqin thetypeofoptimization), shifting a signedintleft by 24 overflows the sign bit and triggers undefined behavior in C11/C17 (§6.5.7p4), caught by UBSan'sshift-basecheck when built without-fwrapv:Changes:
uint32_tinM2/M3/M4and cast the result tointso the variadic argument type matchesva_arg(ap, int)incode_match().uint32_tincode_match()to avoid implementation-defined signed right shifts on negative values.(Supersedes #367, which leaves
M4with unsigned typeuint32_tmismatched withva_arg(ap, int)whenop4 >= 128and does not update the right shifts incode_match().)