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 11 days ago. Updated 11 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.

Actions

Also available in: PDF Atom