Project

General

Profile

Actions

Bug #22518

closed

String#unpack("m") computes the buffer size with an overflowing multiplication

Bug #22518: String#unpack("m") computes the buffer size with an overflowing multiplication

Added by mame (Yusuke Endoh) 3 days ago. Updated 2 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127372]

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)
Actions

Also available in: PDF Atom