Project

General

Profile

Actions

Bug #8742

open
UK

base64: SCBase64Decode creates an out-of-bounds slice when callers allocate only the decoded size

Bug #8742: base64: SCBase64Decode creates an out-of-bounds slice when callers allocate only the decoded size

Added by Uwez Khan 10 days ago. Updated 9 days ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

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 Actions #1

  • 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.

Actions

Also available in: PDF Atom