Project

General

Profile

Actions

Bug #8742

open
UK 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 about 1 month ago. Updated 14 days ago.

Status:
In Progress
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 about 1 month 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.

PA Updated by Philippe Antoine 15 days ago Actions #2

  • Status changed from Feedback to In Review

PA Updated by Philippe Antoine 15 days ago Actions #3

  • Status changed from In Review to Feedback
  • Assignee set to Uwez Khan

PA Updated by Philippe Antoine 14 days ago Actions #4

  • Status changed from Feedback to In Progress
Actions

Also available in: PDF Atom