Skip to content

[10.2.x] backport #13210: fix out-of-bounds read in ats_base64_decode#13244

Open
dkgkdfg65 wants to merge 1 commit into
apache:10.2.xfrom
dkgkdfg65:backport/base64-oob-10.2.x
Open

[10.2.x] backport #13210: fix out-of-bounds read in ats_base64_decode#13244
dkgkdfg65 wants to merge 1 commit into
apache:10.2.xfrom
dkgkdfg65:backport/base64-oob-10.2.x

Conversation

@dkgkdfg65
Copy link
Copy Markdown

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

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants