You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IO#pwrite/#pread buffer fallback: huge offset overflows into a Go panic, large offset allocates the hole in memory #973
When the file cannot be reached by path, IO#pwrite and IO#pread fall back to the stream's buffer, and that fallback computes off+len(data) in int.
A huge offset overflows the sum, and a Go runtime panic reaches Ruby as an ArgumentError.
A large but valid offset materialises the hole in memory, where MRI writes a sparse file.
Affected code:
internal/vm/io_descriptors.go ~:365-368 (the pwrite buffer fallback)
internal/vm/io_descriptors.go ~:350 (the pread buffer fallback)
These lines are pre-existing. The open pull request Refs #970 made them the fallback path only.
Reproduction (found by audit)
f=File.open("t.bin","r+")File.unlink("t.bin")# forces the buffer fallbackf.pwrite("AB",2**63-1)# rbgo: ArgumentError "runtime error: slice bounds out of range"f.pread(1,2**63-1)# rbgo: the same runtime panic messagef.pwrite("AB",2**27)# rbgo allocates ~128 MB; 2**40 would exhaust memory (inferred, not run)
MRI writes to the descriptor, which is sparse.
A Bignum offset raises TypeError in rbgo, where MRI raises RangeError.
Fix
Check off > maxInt - len(data) before slicing and raise as MRI does (Errno::EFBIG or Errno::EINVAL from pwrite(2); measure which).
Cap the fallback buffer growth with a stated limit, or refuse the operation when the path is gone rather than growing memory to the offset.
Add bomb tests that assert a REFUSAL, run under GOMEMLIMIT.
Prior art: priorart "pwrite pread huge offset overflow slice bounds" at 2026-11-21 20:43 CET reported prior art; checked: priorart 'pwrite pread huge offset overflow slice bounds': 206 hits, none on offset overflow; #593 and #347 introduced pread/pwrite, #970 made this the fallback
Activity