On Sat, 22 Nov 2025, 20:08 Andreas Schwab, <[email protected]> wrote:

> On Nov 21 2025, Chet Ramey wrote:
>
> > Yes, this defeats the bash check. I tend to agree with kre that this
> is a Linux kernel bug, but here we are.
>

For these virtual files where it *always* fails, yes that's a bug, but in
general no, because…

This can happen with any file (even "normal" regular ones) if another
> process is modifying it just between the stat and the read calls.
>

(Agreed.)

The correct way to check whether a whole file has been read is to keep
reading until you get a short read.

This implies, for example, that the buffer should be (at least) one byte
larger than the expected size, so that you will normally get a short read
straight away.

But if you read a full buffer, just loop, reading until you get to the end
of the file (expanding the buffer as needed).

> + #if 0
> >         if (nr != file_size)
> >       nr = -1;                /* XXX - didn't get the whole file */
> > + #endif
>

This block is based on fragile assumptions and should be deleted (and
replaced with something that will actually read the whole file).

A short read is never an error, as you can see from the fact that errno
> wasn't set.


Yep.

-Martin

PS: mmap with a fallback to malloc+read ?

>

Reply via email to