Bug #9076
closedlua/hashlib: u32 truncation of Lua string lengths (>4 GiB)
Description
- Status: present in
main(9b7938aec); hardening - Class: silent length truncation (u32) on Lua string inputs
- Component:
src/util-lua-hashlib.c(all update/digest/hexdigest paths),rust/src/ffi/hashing.rs(u32 lengths)
Description¶
Lua string lengths are size_t, but every hashlib entry point casts to uint32_t before the FFI:
util-lua-hashlib.c (uint32_t)data_len / (uint32_t)buf_len at lines 80, 131, 146, 189, 240, 254, 297, 348, 362.
A Lua string larger than 4 GiB is therefore hashed only for len mod 2^32 bytes, producing a silently wrong digest. Memory-safe (the Rust slices never leave the real buffer) and unreachable under the rule/transform allocation limit (default 512 KB); only output scripts (deliberately unlimited) with multi-GB data could hit it.
Fix direction¶
Reject data_len > UINT32_MAX with luaL_error, or widen the FFI to size_t for the buffer lengths.
Test¶
Unit-level rejection test (mock/short-circuit) or a lua-hashlib-huge-len case documenting the chosen behavior.
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