Project

General

Profile

Actions

Bug #9076

closed
VJ VJ

lua/hashlib: u32 truncation of Lua string lengths (>4 GiB)

Bug #9076: lua/hashlib: u32 truncation of Lua string lengths (>4 GiB)

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); 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.


Subtasks 1 (0 open — 1 closed)

Bug #9326: lua/hashlib: u32 truncation of Lua string lengths (>4 GiB) (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom