Repository navigation
fix heap overflow on short input in avx2 Base64Encode - #1137
Open
metsw24-max wants to merge 1 commit into
Open
metsw24-max wants to merge 1 commit into
metsw24-max wants to merge 1 commit into
Conversation
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.
Heap overflow on short input in Avx2 Base64Encode
Avx2::Base64Encodecomputessize24 = AlignLoAny(size - 23, 24)with nosize >= 23guard, so any input under 23 bytes wraps the subtraction and the tail loop boundsrc + size3 - size24lands 16 or 40 bytes past the input. The encoder then reads pastsrcand writes 24 to 88 bytes past the documented(size + 2) / 3 * 4output, depending on size and compiler. Valid short input is enough, for example a 16-byte digest, andSimdBase64Encodehas no length check of its own.Fix
Added the guard the Sse41, Neon and Sve2 encoders and
Avx2::Base64Decodealready use, which should keep the backends consistent.Notes
SimdAvx2Base64.cpp:130forsize = 20, and a stack-buffer-overflow WRITE for a 5-byte string with the same buffer setup as theSimd::Base64Encode(std::string)wrapper.Base64EncodeAutoTestnow covers short sizes and compares a guard region after the output; it fails before the fix and passes after.Test -m=apasses with GCC 13 on x86_64 (AVX2, under Rosetta) and aarch64 (NEON). The AVX-512 and SVE builds compile, but I could not run them here. The guard is one compare per call and timing looks unchanged within noise.