Project

General

Profile

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

Added by Victor Julien 2 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
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:

  1. Empty input errors. SCBase64Decode() returns 0 for len 0 and for real decode errors, and the C wrapper maps n 0 to luaL_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.
  2. 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". The SCBase64Mode enum 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 == 0 handling) 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).


Subtasks 1 (0 open — 1 closed)

Bug #9325: lua/base64: empty input errors; RFC2045/RFC4648 return partial data without error (8.0.x backport)ClosedVictor JulienActions

JI Updated by Jason Ish about 1 month ago Actions #1

  • Status changed from New to In Review

MR1382

JI Updated by Jason Ish about 1 month ago Actions #2

  • Assignee set to Victor Julien

JI Updated by Jason Ish 27 days ago Actions #3

  • Subtask #9325 added

JI Updated by Jason Ish 26 days ago Actions #4

  • Status changed from In Review to Closed

JI Updated by Jason Ish 8 days ago Actions #5

  • Private changed from Yes to No
Actions

Also available in: PDF Atom