Actions
Bug #22518
closedString#unpack("m") computes the buffer size with an overflowing multiplication
Bug #22518:
String#unpack("m") computes the buffer size with an overflowing multiplication
Description
(send - s + 3) * 3 / 4 overflows where long is 32-bit: an input of about 700 MB is rejected, and an input of about 1.4 GB makes it allocate a buffer too small.
# On a platform where long is 32-bit (tested with a 32-bit build, gcc -m32):
("A" * 1_450_000_000).unpack1("m").bytesize
# expected: 1087500000
# actual: [BUG] probable buffer overflow: 1087500000 for 13758178
("A" * 800_000_000).unpack1("m").bytesize
# expected: 600000000
# actual: negative string size (or size too big) (ArgumentError)
Updated by mame (Yusuke Endoh) 10 days ago
Updated by mame (Yusuke Endoh) 9 days ago
- Status changed from Open to Closed
Applied in changeset git|9deaec155c201ac11342adbd416bfeba42031d27.
Compute the buffer size of unpack("m") without overflow
(send - s + 3) * 3 / 4 overflowed for an input of about 700 MB where
long is 32-bit. Divide before multiplying, as each 4 characters decode
to at most 3 bytes.
[Bug #22518]
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Updated by nagachika (Tomoyuki Chikanaga) 5 days ago
- Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: DONE, 4.0: REQUIRED
ruby_3_4 d7532ae1559ac0741312321119498bd7453680c1 merged revision(s) 9deaec155c201ac11342adbd416bfeba42031d27.
Updated by k0kubun (Takashi Kokubun) 3 days ago
- Backport changed from 3.3: REQUIRED, 3.4: DONE, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: DONE, 4.0: DONE
ruby_4_0 b4b3650232e550b418e66b9140fba41a4526aecb merged revision(s) 9deaec155c201ac11342adbd416bfeba42031d27.
Actions