Bug #8742
openbase64: SCBase64Decode creates an out-of-bounds slice when callers allocate only the decoded size
Description
SCBase64Decode constructs its output slice using the encoded input length:
from_raw_parts_mut(output, len)
Several in-tree callers allocate only get_decoded_buffer_size(input_len), which is the correct decoded size for Base64.
Although the decoder only writes the decoded bytes and does not currently overwrite memory, the constructed slice extends beyond the backing allocation, making the unsafe block create an invalid Rust slice.
Proposed fix:
- Size the output slice using get_decoded_buffer_size().
- Reuse base64::get_decoded_buffer_size() instead of duplicating the calculation.
- Perform the arithmetic in u64 to avoid overflow when computing the decoded buffer size.
This matches the expectations of all existing in-tree callers while preserving the current API.
SB Updated by Shivani Bhardwaj 9 days ago
- Status changed from New to Feedback
Could you please tell what's the effect of the bigger output array?
Please share a testcase if you have. Thank you.