[10.2.x] backport #13210: fix out-of-bounds read in ats_base64_decode#13244
Open
dkgkdfg65 wants to merge 1 commit into
Open
[10.2.x] backport #13210: fix out-of-bounds read in ats_base64_decode#13244dkgkdfg65 wants to merge 1 commit into
dkgkdfg65 wants to merge 1 commit into
Conversation
When the base64 alphabet prefix length was not a multiple of four, the decode loop ran one iteration past the prefix, reading input bytes out of bounds and then reading inBuffer[-2] in the trailing adjustment. Found with AddressSanitizer. Decode only complete 4-character groups and handle a 2- or 3-character tail explicitly, dropping a lone trailing character. Decoded length and bytes are unchanged for every well-defined input; only the out-of-bounds reads are removed. Add unit_tests/test_ink_base64.cc covering both alphabets, round-trips, in-place decode, undersized buffers, and truncation. Inputs sit in exact-size heap buffers so ASan faults on the old decoder and passes after the fix. (cherry picked from commit 1e1dd1a)
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.
10.2.x is missing the base64-decode bounds fix that's on master (#13210). On 10.2.x ats_base64_decode walks the input in 4-char groups but doesn't guard the tail when the length isn't a multiple of 4, so a crafted non-aligned base64 string reads past the input buffer.
checked it actually over-reads on 10.2.x (not just a missing line): built ats_base64_decode with -fsanitize=address on ubuntu:22.04 and fed a non-4-multiple input. pre-fix ASan reports a heap-buffer-overflow READ just past the buffer and aborts; with the master fix cherry-picked it decodes cleanly. the upstream unit test (test_ink_base64.cc) comes along in the cherry-pick.
clean cherry-pick (-x), original author (Phong Nguyen) preserved. happy to rebase if you'd prefer.
upstream: 1e1dd1a