Skip to content

Let a base64 decoder be told where its input ends - #377

Merged
gennaroprota merged 1 commit into
developfrom
fix/let-a-base64-decoder-be-told-where-its-input-ends
Aug 14, 2026
Merged

Let a base64 decoder be told where its input ends#377
gennaroprota merged 1 commit into
developfrom
fix/let-a-base64-decoder-be-told-where-its-input-ends

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

Decoding base64 means turning 6 bit input into 8 bit output, and a sequence whose length is not a whole number of four character groups ends with bits which do not make up a byte. equal_impl promises to discard them, but for BitsIn < BitsOut it only compares base iterators, so the caller sees one more element to fetch and fill() looks for the missing bits beyond the end of the input. Any length with n % 4 == 1 does it.

Reading the input is the only way the single argument constructor learns where it ends, so it cannot avoid this. The new constructor takes the end as well, and then a value which cannot be completed ends the sequence rather than being sought. The old form keeps its behavior.

Fixes #324.

Decoding base64 means turning 6 bit input into 8 bit output, and a
sequence whose length is not a whole number of four character groups
ends with bits which do not make up a byte.  `equal_impl` promises to
discard them, but for `BitsIn < BitsOut` it only compares base
iterators, so the caller sees one more element to fetch and `fill()`
looks for the missing bits beyond the end of the input.  Any length with
`n % 4 == 1` does it.

Reading the input is the only way the single argument constructor learns
where it ends, so it cannot avoid this.  The new constructor takes the
end as well, and then a value which cannot be completed ends the
sequence rather than being sought.  The old form keeps its behavior.

Fixes #324.
@gennaroprota
gennaroprota added this pull request to the merge queue Aug 14, 2026
Merged via the queue into develop with commit 700fa0a Aug 14, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

from_base64 UNDEFINED BEHAVIOR for invalid base64 string

1 participant