Actions
Bug #9075
closed
VJ
VJ
lua/base64: empty input errors; RFC2045/RFC4648 return partial data without error
Bug #9075:
lua/base64: empty input errors; RFC2045/RFC4648 return partial data without error
Affected Versions:
Effort:
Difficulty:
Label:
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: API semantics (error on empty input; partial decoding without error)
- Component:
src/util-lua-base64lib.c:54-72,rust/src/ffi/base64.rs:88-134
Description¶
Two semantics problems in the Lua decode wrappers:
- Empty input errors.
SCBase64Decode()returns 0 forlen 0and for real decode errors, and the C wrapper mapsn 0toluaL_error("base64 decoding failed")(util-lua-base64lib.c:63-66).base64.decode(""),decode_nopad(""),decode_padopt("")and both RFC variants therefore raise instead of returning"". Empty payloads/buffers are common and attacker-controllable. - RFC modes return partial plaintext without error.
decode_rfc4648("Zm9v!!!")returns"foo",decode_rfc4648("Zm9vYg")returns"foo"(trailing partial quad dropped),decode_rfc2045("<Zm9v$")returns"foo". TheSCBase64Modeenum comment (rust/src/ffi/base64.rs:49-57) says RFC4648 should reject data outside the alphabet, while the userguide says processing stops; callers cannot rely on strict validation.
No memory-safety impact.
Fix direction¶
- Distinguish "empty input" from "error" (separate status or explicit
len == 0handling) and return an empty string. - Decide RFC semantics: either error on invalid/alphabet characters and incomplete trailing quads, or document truncation explicitly; ideally expose the consumed length/status.
Tests¶
lua-base64-empty (all five modes return ""; encode("") returns ""), lua-base64-rfc-partial (pin each mode's behavior for invalid mid-stream chars and trailing partial quads).
JI Updated by Jason Ish about 1 month ago
- Status changed from New to In Review
MR1382
JI Updated by Jason Ish about 1 month ago
- Assignee set to Victor Julien
Actions