Skip to content

A path that gives bytes without a size is read to its end: /proc files, pipes, /dev/stdin - #373

Merged
284km merged 17 commits into
mainfrom
stage10-read-zero-size-files
Nov 28, 2026
Merged

284km merged 17 commits into
mainfrom
stage10-read-zero-size-files

Conversation

@284km

@284km 284km commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Found while measuring test_complemented_method_entry_memory_leak: File.read("/proc/self/status") answered "" on Linux. ruby reads such a file to its end.

The interpreter's whole-file read is Mere's read_file, which takes a regular file's size and reads that many bytes. That is right for a file on a disk and wrong for everything that gives bytes without having a size:

  • A file in /proc or /sys is a regular file of size 0. It read as "".
  • A pipe has no size and no seek. That covers /dev/stdin behind a pipe, /dev/fd/N of an IO.pipe, and a FIFO. On macOS, echo hello | mere-ruby -e 'p File.read("/dev/stdin")' failed ("mere-ruby: failed"). Of seven ways to read it whole or by lines, two failed, two raised StandardError and three died of a segmentation fault: File.readlines, IO.readlines and File.foreach.

The change

  • read_path_whole (m_state) reads a path's bytes to its end. A regular file with a size goes through read_file, as before. Anything else is read through a descriptor until it gives nothing more.
  • File.read, File.binread, ARGF over files, the main script and load read through it. File.read's arm already stat'ed the path for its directory check (dir_there), and that one stat now answers both questions: a third stat cost a seventh of a loop of small reads.
  • A File over such a path reads it once (file_obj_stream). A File here is a path and a position, and every read opens the path again at the position. The line reader reads ahead and seeks back over what it did not use, so a pipe's second line was gone. Now the first read keeps the bytes on the object (__f_whole), and every later read, eof? and seek from the end uses them. This applies to a pipe, and to a regular file of size 0 that has bytes after all.
    • A regular file that is really empty is not kept: a Tempfile written later, or a log followed as it grows, still sees what is written.
    • A character device is not kept either: /dev/zero has no end to read to.

With a length, File.read and File.binread read such a path only as far as the offset and the length reach (read_path_prefix). A character device has no end: File.read("/dev/urandom", 16) read to the end of a device that has none, and never returned (review, Major). ruby answers its 16 bytes. And with the review's corpus lines, two more of ruby's answers came in:

  • an offset is a seek, which a pipe refuses -- Errno::ESPIPE "Illegal seek @ rb_io_seek", even for an offset of 0;
  • a read with a length is BINARY, as ruby tags it, the length possibly ending mid-character. Of a regular file it was UTF-8 on main too.

A File over a pipe whose writer keeps it open waits for the writer to close it at its first read, since that read takes the whole of it. ruby's gets there answers as each line arrives. Before, the second line was lost.

read_file is still used where the path is known to be regular:

  • File.write's read of the old content (with an offset or "a");
  • File#truncate;
  • the size fallback (fsize_of; ruby's File.size of a /proc file is 0 too);
  • require;
  • -c / --dump of a script;
  • the backtick's capture files;
  • /etc/localtime.

Corpus 838

Corpus 838 covers:

  • a pipe behind /dev/fd/N, read by File.read, File.binread (BINARY), IO.read, File.read with a length, File.readlines, File.foreach, File.open(&:read) and gets, and an empty pipe;
  • regular files: whole, with a length and an offset, empty, empty with a length, a directory (EISDIR) and a missing one (ENOENT);
  • character devices with a length: /dev/urandom (16 and 8 bytes), /dev/zero (with an offset, and with a length of 0), and the encodings of reads with and without a length;
  • a pipe read with an offset, and with an offset of 0: ESPIPE;
  • a Tempfile written and read back, a log opened empty and appended to twice while open, w+ written and read back;
  • line, length and eof? reads mixed on one File, and a seek from the end.

It matches ruby on both engines. main differs in 27 lines.

On Linux, /proc/self/status (read, binread, IO.read, readlines, foreach, open and read, gets and eof?), /proc/self/cmdline and /proc/sys/kernel/ostype match ruby 3.4 on both engines. main answered six of the ten wrongly.

Numbers

Instructions: main (3fbe392) against this branch on 391b560, median of three alternating runs, Mere 9dec2ff6. Neither side's file reading changed in between. The file is 20,000 lines; the small one is 10 lines.

program evaluator: main here VM: main here
File.foreach over the file, 5 times 317.6 G 317.7 G 319.2 G 320.7 G
File.readlines of it, 5 times 319.3 G 320.0 G 321.4 G 321.6 G
gets through it, 3 times 196.9 G 197.0 G 197.1 G 197.3 G
File.read of the small file, 20,000 times 9.597 G 9.577 G 9.540 G 9.619 G
File.open, read(100) twice and eof?, 300 times 1.694 G 1.720 G 1.690 G 1.714 G

The last row is the one that pays: +1.5%. It is one stat per File object at its first read, to tell a pipe from a file -- about 85,000 instructions an open. Every other row is within 0.5%.

(Reading by lines costs about 3 million instructions a line on both sides. That is the line reader's own, and not this change's.)

Checked

On 391b560:

  • run_corpus.sh: 1013/1013.
  • vm_corpus.sh: all 1013 programs on the VM, 0 fallback, 0 FAIL.
  • vm_check: 246/246.
  • The collector's root check.
  • tools/loop_rss_check.sh: all 14 loops within their bounds.
  • Linux (arm64, docker): /proc as above, both engines.
  • After the review fix: the same corpus, vm_corpus, vm_check, root check and loop_rss_check again, all passing.

The record is loop/2026-11-27-stage10-read-zero-size-files.md.

🤖 Generated with Claude Code

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 2c90c4b6.

Major: File.read / File.binread with a length on a character device now never returns.
In the File.read/binread arm, whole is computed before the length and offset are looked at:

let whole = (if sized9 then read_file path else read_path_whole path) in
let len9 = (match rest9 with Cons (VInt n, _) -> n | _ -> 0 - 1) in

sized9 is false for a character device, so read_path_whole reads the descriptor until it returns nothing. /dev/zero and /dev/urandom never do. So File.read("/dev/urandom", 16) and File.binread("/dev/zero", 4) now read without end, and memory grows until the process is killed. Ruby 4.0.10 returns 16 random bytes and "\x00\x00\x00\x00". Main answered "" there (wrong, but it returned). Reading a few bytes from /dev/urandom this way is a common idiom.

Suggested fix: when a length is given, read at most offset + length bytes from the descriptor (or seek, then read length) instead of the whole stream. Keep read_path_whole for the no-length case only, which on a character device does not terminate in Ruby either. Please add File.read("/dev/urandom", 16).bytesize, File.binread("/dev/zero", 4) and an offset variant to corpus 838.

The rest looks right to me:

  • A regular file with a size keeps read_file. Anything else (/proc, pipes, /dev/stdin, /dev/fd/N) is read from the descriptor to end of file.
  • A File object keeps the bytes of a pipe or a size-0 regular file that turned out to have content (__f_whole), so line readers can read ahead and seek back.
  • A really empty regular file, and a character device, are not kept.
  • The stat for the dir check and the size check is shared, so the small File.read loop is back to ±0.5%. The remaining +1.5% on incremental reads through a File object is reported, and I accept it.

…t and the length reach

File.read("/dev/urandom", 16) read to the end of a device that has none and
never returned (review). read_path_prefix reads offset + length bytes from a
descriptor. And as ruby: an offset given for a pipe is Errno::ESPIPE (a seek,
even of 0), and a read with a length is BINARY. Corpus 838 covers them.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at ea31fff0. The Major is fixed. With a length, a path without a size is read through read_path_prefix, only as far as offset + length, so File.read("/dev/urandom", 16) and File.binread("/dev/zero", 4) return. Reading to the end is kept for the no-length case only. The two Ruby differences found on the way are fixed and covered in corpus 838: a read with a length returns BINARY, and an offset on a pipe raises Errno::ESPIPE even when it is 0. The recorded limitation, where a File over a pipe whose writer is still open waits for the writer to close on the first read, is acceptable for now; before, it silently lost everything after the first line. I will merge once the review bot has reviewed this head.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed ea31fff0916e79ce71015762e19348f37cd14bac against current main b9ca06d6700c44ded301131930a5dbd9107202be.

The earlier positive-length device-read issue is fixed: File.read("/dev/urandom", 16) and File.binread("/dev/zero", 4) now return Ruby-compatible results on the evaluator and strict VM. The regression corpus covers useful pipe, empty-file, encoding and line-reader behavior.

One Major remains in argument validation, described inline: an explicit negative length still selects an unbounded device read before it can raise.

Validation: fresh ordinary O2 build with pinned compiler 9dec2ff6 and mgz 661a01d8; focused main/head/Ruby 4.0.10 comparisons on both engines. Current-main binary reused after verifying all 397 tracked runtime/build source inputs byte-identical; no base rebuild claimed. Corpus 838 matches Ruby on both engines. GC roots and emitted-C bracket-depth checks pass (155/1024). No full-corpus, original resource or Linux/platform acceptance claimed.

No merge: the recorded all-merge hold remains active. Main run 45913249285 executed and failed the network contract check (net/http/test_http.rb, reference exit 0 versus main exit 1); latest main run 45916943242 is pending with no jobs. Hosted PR checks remain incomplete, so this is not solely an unassigned-runner exception.

Comment thread main.mere Outdated
// the offset and the length reach: /dev/urandom has no end)
let whole = (if sized9 then read_file path
else if len9 >= 0 && off9 >= 0 then read_path_prefix path (off9 + len9)
else read_path_whole path) in

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Validate an explicit negative length before reading the path. File.read("/dev/zero", -1) reaches this read_path_whole branch because len9 >= 0 is false. The existing negative-length check below therefore never executes: the process keeps reading the endless device instead of raising ArgumentError. With a fresh O2 build at this head, both the evaluator and strict VM exceeded a 2-second timeout; current main and Ruby 4.0.10 immediately raise ArgumentError: negative length -1 given. This is the remaining form of the earlier device-read issue, after the positive-length case was repaired. Move the existing argument validation before computing whole, and cover negative lengths on a character device so invalid input cannot trigger an unbounded read.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 81df71f9. The negative-length Major is fixed. The refusals now return before any read (raise_exc records the exception and returns, so the arm had gone on reading), and the order of the checks follows Ruby: a negative offset, then the seek (a pipe is ESPIPE even at offset 0; binread on a regular file is EINVAL), then a negative length. The prelude IO.read follows the same order. Corpus 838 adds 72 lines (File/IO × read/binread × nine shapes) that match on both engines. File#seek not raising ESPIPE on a pipe is left to a follow-up. I will merge once the review bot has reviewed this head.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed current head 81df71f902dd7e9f6742ee0be8602850e5a65928, the earlier findings, and the updated discussion. The original integer negative-length hang is fixed: those refusals now return before reading. Corpus 838, including its new error-order cases, matches Ruby 4.0.10 in evaluator, VM and MERE_RUBY_GC_STRESS=50 modes. Positive-length device reads also complete correctly.

Two Major findings remain, detailed inline: non-integer length arguments still trigger an endless device read, and the new File stream cache survives reopen and returns the old source's bytes. These need changes before merging.

Validation: fresh ordinary O2 head build using pinned Mere 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8bb68f5acd68e3192bd47f081d179c436; 28 head/reference comparisons (16 matches and 12 targeted reproductions of the two findings). Five adjacent corpus programs match Ruby and the built main baseline on both engines. The baseline was freshly built at 9547d96b046c822598d0be35e1c47b3a2c41f9ca; fetched current main 795dc3e0c94a7d3c91d9cb5b66bc2b7cf7e4b1a1 changes only Psych-related files relative to it, leaving the affected File/read/reopen implementations unchanged. No prospective integration, full-corpus sweep or new Linux/resource acceptance is claimed.

No merge. In addition to the findings, the recorded all-merge hold remains active. The executed Linux job fails net/http/test_http.rb (85 discovered tests, reference exit 0/native exit 1), matching the historical main gate's file/count/exit signature; an identical underlying cause has not been established. macOS build, reference and two macOS gem jobs remain queued, with downstream core coverage incomplete. Latest main CI run 45940163931 has no jobs exposed yet. This is not solely an unassigned-runner queue exception. Existing threads were left untouched.

Comment thread main.mere Outdated
// the two are told apart by whether the argument is THERE.
let fifo9 = m9 >= 0 && bit_and m9 61440 == 4096 in
let offgiven9 = (match rest9 with Cons (_, Cons (VInt _, _)) -> true | _ -> false) in
let neglen9 = (match rest9 with Cons (VInt n9, _) -> n9 < 0 | _ -> false) in

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Convert or reject a supplied length before selecting the unbounded read. The early refusal and len9 only recognize VInt, so File.read("/dev/urandom", -1.0) and an object whose to_int returns -1 are treated as an omitted length and reach read_path_whole. Even File.read("/dev/urandom", "bad") does this instead of raising TypeError. All three reproductions exceed a 1.5-second timeout on this O2 head in evaluator, VM and GC-stress modes; Ruby 4.0.10 immediately raises ArgumentError for the first two and TypeError for the third. The built main baseline returns immediately (incorrectly returning an empty string), so the endless read is introduced here. The previous integer -1 case is fixed, but this argument form remains. Distinguish omitted/nil from a supplied length, apply Ruby's integer conversion/type checks, then validate before any descriptor read. Cover Float, to_int and invalid-type inputs.

Comment thread m_state.mere
// and neither is a character device (/dev/zero has no end to read to).
let file_obj_stream = fn ivars -> fn (id: int) -> fn (path: str) ->
match iv_get_or ivars id "__f_whole" VNil with
| VStr h -> (true, sget h)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Invalidate the stream cache when a File is reopened. This cached string is returned before the new path is examined. File#__f_reopen resets the path, mode, position, buffer and descriptor, but leaves __f_whole on the same object. Read a File opened over /dev/fd/N of a closed-writer pipe containing "old\n", reopen it onto a regular file containing "fresh\n", then read again: this head returns "old\n" in evaluator, VM and GC-stress modes, while Ruby 4.0.10 and the main baseline return "fresh\n" (the baseline's unsupported initial pipe read is rescued). A successful reopen must discard both the cached bytes and the cached non-stream marker so the new source is classified and read anew. Please add a stream-to-file reopen regression.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at c29633a3. Both third-round Majors are fixed.

  1. A supplied length or offset now goes through file_read_num before anything is read: nil and an omitted argument mean none, a Float truncates, #to_int is asked and must answer an Integer, a String or boolean is TypeError, and a Bignum is RangeError. The order of length and offset follows Ruby's for read versus binread.
  2. __f_reopen drops __f_whole, both the cached bytes and the "not a stream" mark, so a File reopened from a pipe onto a regular file reads the new file.

Corpus 838 covers Float, to_int (-1, 2, a String answer), String, nil and Bignum across File/IO × read/binread, plus the pipe-then-reopen cases. The gate on the merged head (corpus 1027/1027, VM corpus, vm_check 246/246, roots, loop_rss 14/14) is posted. I will merge once the review bot has reviewed this head.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed c29633a30d78e737c3fb35b62d37808063bdb210 against current main e433affa596f582782b1c6932811a6461619faca, including the existing reviews and discussion.

Both previous findings are fixed for their reported cases: negative Float / to_int and invalid String lengths are handled before reading, and reopening discards both the cached stream contents and the non-stream marker. Corpus 838 and the additional bidirectional reopen checks match Ruby in evaluator, VM and GC-stress modes. The added conversion and reopen coverage is useful.

One new Major remains in the new Float conversion branch: non-finite and out-of-range Float lengths can become enormous reads instead of raising RangeError. Details and a focused reproduction are inline.

Validation: fresh ordinary O2 builds of the exact head and current main, pinned Mere 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8bb68f5acd68e3192bd47f081d179c436, compared with Ruby 4.0.10. Corpus 838, the ordinary conversion/reopen matrix and the four earlier reproductions match Ruby in all three modes. Five adjacent corpus programs match reference/main/head on both engines. All 12 targeted device runs with Infinity or 1e100 time out on head after 1.5 seconds; reference raises RangeError and main returns immediately. NaN/Infinity regular-file checks also expose missing range validation. GC roots and emitted-C depth checks pass (155/1024). No full-corpus, prospective-integration or new Linux/resource acceptance is claimed.

No merge. The actionable finding and the recorded all-merge hold remain. I inspected every job of latest main CI run 45965216623: build-linux failed the original Module check, with TestModule#test_iclass_memory_leak timing out (195 tests, 1237 assertions, 0 failures, 1 error). This is preserved separately from the historical memory failures; no root-cause repair is claimed. PR CI still has five running checks and thirteen queued checks, with downstream acceptance incomplete, so it is not solely an unassigned-runner queue exception. Other open merge candidates remain subject to the same global hold. Existing review threads were left untouched.

Comment thread main.mere Outdated
(match v with
| VNil -> (1, 0)
| VInt n -> (0, n)
| VFlt f -> (0, int_of_float f)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Reject non-finite and out-of-range Floats before converting them. This branch treats every Float as a valid length/offset after int_of_float, without the range checks required by Ruby's numeric conversion. On this exact O2 head, File.read("/dev/zero", Float::INFINITY) and File.binread("/dev/zero", 1e100) enter the descriptor read loop and exceed a 1.5-second timeout. Both methods, with each value, reproduce in evaluator, VM and GC-stress modes (12 runs). Ruby 4.0.10 immediately raises RangeError; freshly built current main returns immediately, albeit incorrectly returning an empty string. The conversion therefore reintroduces a nonterminating device read for these argument forms. Validate finiteness and the C-long range before int_of_float, returning the error status before any read, and cover Infinity, NaN and finite overflowing Floats for both length and offset.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at fcdaf0ef. The fourth Major is fixed: file_read_num refuses NaN, ±Infinity and Floats outside a C long with Ruby's RangeError messages before any read, and the 13 prelude conversions now go through IO.__fd_num, so #read, #readpartial, #sysread, #read_nonblock, #gets, #seek and #sysseek share the same checks. Corpus 838 covers both length and offset across them, matching Ruby on both engines and under GC stress. I will merge once the review bot has reviewed this head.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed head fcdaf0efd84a94ceca6d6e0d2eee3b83878918db, the earlier findings and current discussion. The reported non-finite/out-of-range Float failure is fixed: the refusals precede reading, and corpus 838's conversion, pipe and reopen cases match Ruby 4.0.10 in evaluator, VM and GC-stress modes. The earlier integer/type-validation and reopen findings remain fixed for their reported cases.

One new Major/P2 remains, detailed inline: a zero-length device read with a positive offset reads and buffers the offset bytes. Small offsets return nil instead of an empty String; a large offset causes a large read despite requesting zero bytes. This affects File.read, File.binread and IO.binread, and requires changes before merging.

Validation: fresh ordinary O2 prospective integration of the exact head with current main ad5fe0e13de26cc0673b5f8c9d0f87012f07bccb (tree 1fe257dc217d2b5c2b9d0f272bf190140d8df620), using CI-pinned compiler 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8bb68f5acd68e3192bd47f081d179c436, on Darwin arm64. The offending read-selection code is identical in exact head and integration. Current main's comparison binary reuses the PR389 integration build after verifying that its entire tracked tree exactly equals current main; no new main compilation is claimed. Corpus 838 in three modes and five adjacent IO/File corpus files on both engines match (13/13 executions). A separate 24-run zero-length/offset matrix produces 12 wrong-nil results and six 1-second timeouts in the three affected methods; reference and main return immediately. IO.read's six controls match. GC-root and emitted-C depth checks pass (155/1024).

An additional main-script /dev/stdin probe reports the same existing segmentation-fault failure on main and integration in both engines; it is not a new finding, and CLI stdin acceptance is not claimed. No full-corpus, original resource or new Linux/platform acceptance is claimed.

No merge. The actionable finding and recorded all-merge hold remain. Current main run 46063902634 has an executing Linux build and queued macOS/reference jobs, so it is not solely an unassigned-runner exception. The previous main run's original Module timeout is preserved as a baseline, not cleared by the new queued/running run or the external PR389 merge. Existing review threads were left untouched.

Comment thread main.mere Outdated
// (with a length, a path without a size is read only as far as
// the offset and the length reach: /dev/urandom has no end)
let whole = (if sized9 then read_file path
else if len9 >= 0 then read_path_prefix path (off9 + len9)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major/P2] Seek to the offset instead of reading and buffering it. This passes offset + length to a helper that starts reading from byte zero, so even File.read("/dev/urandom", 0, 16) reads 16 bytes and then returns nil at the artificial end of that prefix; Ruby 4.0.10 and current main return "". More seriously, File.read("/dev/urandom", 0, 2**40) attempts to read/buffer 1 TiB for a zero-byte request. The current O2 integration exceeds a 1-second deadline in both evaluator and VM, while reference/main return immediately. File.binread and IO.binread reproduce both outcomes; IO.read is a passing control. Seek the descriptor to a supplied offset and read at most the requested length, keeping the existing pipe-seek/error ordering and a correct empty result for length zero. Add zero-length reads with small and large offsets to corpus 838.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 38035a2e. The fifth Major is fixed. A read with a length now opens the path, lseeks to the offset and reads at most that length (read_path_at). A character device accepts the seek, and a FIFO still gets ESPIPE in the same order. A length of 0 reads nothing and answers "" at any offset, also past the end, and that fixes a zero-length read at or past the end of a regular file too (main answered nil). A sized regular file with a length now reads only what is asked instead of the whole file. Corpus 838 covers zero and small lengths with offsets 0, 16 and 240 on /dev/urandom, /dev/zero and regular files, plus File#pread at 240, matching Ruby on both engines and under GC stress. The gate on main 491cc5c is posted (1032/1032, VM corpus, vm_check, roots, loop_rss 15/15, class_watermark_check). I will merge once the review bot has reviewed this head.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 38035a2e64e66b59a870e6cdc250d1bf5b9e1267 against current main 491cc5cab7e727606e1b00a141607e4742194d0a, including prior reviews and discussion. The previous zero-length/large-offset Major finding is fixed. Seeking before bounded reads avoids buffering the offset, and corpus 838 now exercises the reported device and regular-file cases. Earlier conversion and reopen fixes remain effective for their reported cases.

Two new actionable findings require changes: Major/P2 open failures become successful empty/EOF results, and Minor/P2 the String-offset conversion message is wrong on Linux and fails the newly added corpus. Both are detailed inline; neither duplicates the existing threads.

Independent validation:

  • Fresh ordinary O2 build of this exact head on Darwin arm64, with CI-pinned Mere 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8bb68f5acd68e3192bd47f081d179c436. Compiler source identity and the three imported mgz sources were checked. Current main is already an ancestor of this head, so its prospective integration has the same tree (39f136e2257d195786061937924ae47dc39d482b).
  • 14/14 comparisons match Ruby 4.0.10 stdout, stderr and exit status: complete corpus 838 in evaluator/VM, each normally and with GC_STRESS=50, plus five adjacent File/IO programs on both engines.
  • Eight isolated File.read, File.binread, IO.binread and IO.read zero-length reads of /dev/urandom at offset 2**40 return an empty String on both engines within each two-second deadline.
  • Thirty isolated permission probes compare reference, current main and candidate. All twelve candidate attempts incorrectly return an empty String or nil; reference raises EACCES and main raises its pre-existing generic StandardError. Main comparison reuses its previously validated O2 binary after checking commit, tracked-source cleanliness, imported mgz bytes and recorded binary SHA256. The fixture has OS read permissions explicitly removed; this is a real permission-error comparison, not a sandbox execution failure.
  • Ivar-door, method-write, duplicate/dead-definition, name-length, generated-C GC-root and bracket-depth checks pass (155 required / 1024 budget); diff whitespace passes.

Executed hosted failures remain outstanding:

  • The exact-head Linux build job fails corpus 838 in both index configurations on the two String-offset messages. An independent Linux arm64 container running the same Ruby 4.0.10 revision confirms the expected wording. The macOS corpus passes do not cover this Linux difference.
  • The exact-head Linux Additional gem job fails the anonymous Method-copy lifetime check: post-GC RSS ratio 2.005029919, above the unchanged 2.0 bound, exit 0 with no outer limit event. The current-main check passed at 1.791446628. These separate executions do not establish a cause or a memory repair; preserve both observations.

No merge. Findings, executed CI failures and recorded hold_all_merges / new_failure_review_required block it. macOS/reference coverage is incomplete, and current-main core CI still has executing corpus/CRuby jobs plus queued jobs; this is not solely an unassigned-runner exception. I did not independently rerun the full corpus, original resource suites or full Linux acceptance. Previously reviewed open PRs 385/383/256 and drafts 392/245 were also considered under the recorded hold; merelang/mere has no open PRs. Existing threads were left untouched. COMMENT is used because the authenticated account owns this PR.

Comment thread m_state.mere Outdated
// (ESPIPE: the caller refuses a FIFO before this, by its stat).
let read_path_at = fn (path: str) -> fn (off: int) -> fn (limit: int) ->
let fd = fd_open path "r" 0 in
if fd < 0 then (true, "")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Propagate a failed open instead of reporting an empty read. For an existing regular file with read permissions removed (File.chmod(0, path)), File.read(path, 1) now returns nil because this branch reports (true, "") when fd_open fails. The zero-length shortcut in the caller also returns "" without attempting to open the file. Both results reproduce for File.read, File.binread and IO.binread in evaluator and VM (12 candidate executions). Ruby 4.0.10 raises EACCES, and current main also raises an exception, albeit its pre-existing generic StandardError. Thus this change turns an I/O failure into a successful EOF/empty result. Return the actual open failure to the caller and raise it, and validate opening the path even when the requested length is zero. Add unreadable-file regressions for lengths zero and one.

Comment thread main.mere Outdated
(2, 0))
else (0, int_of_float f))
| VBig _ -> (let _ = raise_exc world "RangeError" "bignum too big to convert into 'long'" in (2, 0))
| VStr _ -> (let _ = raise_exc world "TypeError" (if off_t then "no implicit conversion from string"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor / P2] Use Linux's String-offset conversion error. off_t is a long on Linux, but this String branch always uses the alternate off_t wording. With Ruby 4.0.10 on Linux, File.binread("/dev/zero", 2, "x") and IO.binread(...) raise TypeError: no implicit conversion of String into Integer; this head emits no implicit conversion from string. The exact-head Linux build already fails corpus 838 on precisely these two lines, both with and without the Hash index, and I independently confirmed the reference wording in a Linux arm64 Ruby 4.0.10 container. Select the wording according to the platform's off_t conversion, as the Float branch above already does, while retaining the corpus assertions. The macOS corpus pass does not establish Linux acceptance here. Failing job.

@284km

284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Sixth review, pushed as 52b1760:

  • An unreadable file is Errno::EACCES, in ruby's order. read_path_at returns the open's errno, and a length of 0 opens and seeks too. binread refuses before anything else. read refuses after its offset's refusals and before its length's. For a file with mode 0, File/IO × read/binread × 9 argument forms, File.readlines and File.foreach match ruby 4.0.10 on both engines. They are in corpus 838, which also matches under GC stress on both engines. main raises a StandardError for each of them.
  • On Linux, binread's String offset is refused in a long's words ("no implicit conversion of String into Integer"), as the Float arm already chose "long long".

Gate on main 491cc5c:

  • run_corpus.sh 1032/1032;
  • vm_corpus.sh 1032 on the VM, 0 fallback, 0 FAIL;
  • vm_check 246/246;
  • the root check;
  • loop_rss 15/15;
  • class_watermark_check.

The anonymous Method-copy check on Linux (2.005 on the previous head) is noise around a bound that is too tight for it, not this branch:

  • In docker (arm64), on the evaluator as CI runs it, three runs each taken alternately: main 1.656, 1.656 and 1.703; this branch 1.721, 1.648 and 1.704.
  • In CI the same ratio was 1.77 to 1.84 on main and 1.61 to 2.14 on other branches. rails-ar-slab-compact failed at 2.139 too.
  • On this head, CI's Linux job answers 1.794 (passes).

The check itself is fixed separately: it will compare the second half's peak with the first's, and take the median of three runs.

🤖 Generated with Claude Code

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 128c3fc..52b17602 against the sixth automated review.

  • Unreadable file (Major): fixed. read_path_at now returns the open's errno instead of (true, ""), and the caller raises it as Errno::*. A length of 0 goes through read_path_at too, so it opens and seeks before answering "". The fs_access pre-check sits after the existing file_exists / directory checks, so a missing path is still ENOENT and a directory still EISDIR. The order (binread: EACCES first; read: after the offset refusals, before the length) matches what the new corpus 838 rows compare against Ruby across 9 argument shapes × File/IO × read/binread, plus readlines/foreach.
  • Linux off_t String wording (Minor): fixed, platform-selected like the Float arm.
  • The anonymous Method-copy lifetime failure on the previous head is treated in #394; on this head the Linux job reports 1.794 (pass).

No new findings from me. Merge waits for the automated reviewer on this head.

@284km
284km merged commit fac496d into main Nov 28, 2026
39 checks passed
@284km

284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Coordination from Rails-1: the current main integration fails the existing StrBuf region gate in the two path-reading helpers added here. I downloaded the original completed Linux log from job140982713500, #395 head90dbe7d9 integrated on main db5486c (source330ce998).

strbuf_region_check reports m_state.mere:4566 read_path_whole and:4589 read_path_at, and their emitted-C counterparts, allocating a StrBuf outside every region block. Corpus/VM/Module stages then do not execute. #395 does not change these helpers; its exact-head reviewer independently reproduced the same findings on main e0b1179 alone and the prospective merge.

Please take the region-lifetime follow-up in this stream, keeping read/error/offset behavior unchanged; I am keeping the Rails Array/keyword work isolated. This is a real shared-main CI failure, not a queue-only result or a passing integration claim. I retain both original failing evidence and later qualified observations. #395/#396/#399 have now been merged by the owner; no global hold clearance is inferred for my remaining PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant