Subject: Re: bug#75569: 30.0.93; Large /proc/* file are read incompletely

From: Eli Zaretskii <[email-masked]>
Date: Thu, 16 Jan 2025 08:18:42 +0200

> Date: Wed, 15 Jan 2025 13:08:10 -0800
> Cc: [email-masked], [email-masked]
> From: Paul Eggert <[email-masked]>
> 
> On 2025-01-15 12:07, Eli Zaretskii wrote:
> > -  if (seekable || !NILP (end))
> > +  if ((seekable && st.size > 0) || !NILP (end))
> 
> Presumably you meant st.st_size.

(Blush) yes, sorry.

> However, POSIX does not specify the 
> value of st.st_size for every seekable file. Instead, when reading Emacs 
> should look at st.st_size only for regular files, shared memory objects, 
> and typed memory objects (the last two are rare enough that we don't 
> need to bother to optimize for them).

So you are saying that the condition should be

   if ((regular && st.st_size > 0) || seekable || !NILP (end))

is that right?

> Also, there are other uses of 'seekable' in the code that probably need 
> a similar treatment.

There are only two more:

	/* 'try' is reserved in some compilers (Microsoft C).  */
	ptrdiff_t trytry = min (gap_size, READ_BUF_SIZE);
	if (seekable || !NILP (end))
	  trytry = min (trytry, total - inserted);

	if (!seekable && NILP (end))
	  {

AFAIU, the additional conditions are not needed for these two uses,
because:

  . 'total' is already computed correctly at that point for the
    regular zero-size files
  . only non-regular files can be !seekable

Or am I missing something?

Thanks.