Review report

core: PR #36210

1 minor finding · 1 suggestion

Findings

Link

[minor] · POSIX read-failure tests use a write-only stream

The read, ignore, and BufferedFile checks do not reach the closed-descriptor read failure they describe, and on musl can pass because of stale errno.

Location: src/test/streams_tests.cpp:219 (head).

Details and suggested fix

On POSIX, open_for_failing_read opens the stream with "wb", so each read subtest calls fread() on a write-only FILE*. On musl, this fails in __toread() before the read reaches the descriptor closed by break_direction, and it does not set errno. The errno-suffix check can then pass using a stale EBADF, including one left by the previous block's ~AutoFile() closing an already-closed descriptor. These cases therefore depend on test order and do not show that read(), ignore(), or BufferedFile::Fill() report the error from the failing call. This also conflicts with the comment saying the FILE is opened in the correct direction. Open the stream with open_unbuffered("rb"); also set errno = 0 before fn() in check_io_failure so stale values cannot satisfy the check.


Optional improvements

Link

[suggestion] · A stale EOF flag hides the failed seek's OS error

If a read has set EOF, a later failed seek can still report "end of file" and omit the OS error; no current caller that triggers this sequence was identified, so production impact is unconfirmed.

Location: src/streams.cpp:41 (head).

Details and suggested fix

AutoFile::seek() chooses its exception message using feof(), but end-of-file does not cause fseek() to fail. A successful seek clears the EOF indicator, while a failed seek need not; musl clears F_EOF only after the underlying seek succeeds. Thus, if read() reaches EOF and a later seek fails, the exception can say "AutoFile::seek: end of file" and discard the captured error. For example, seek(-1, SEEK_SET) fails with EINVAL. The conditional message predates this change, but this change adds the OS error to the same line, and the new seek test covers only a fresh stream. No current caller that seeks after a read has set EOF was identified, so production impact is unconfirmed. Always report "AutoFile::seek: fseek failed: " + SysErrorString(err) when the seek fails.


Coverage details