#1042755 patch: doesn't respect first EOF

Package:
patch
Source:
patch
Description:
Apply a diff file to an original
Submitter:
наб
Date:
2023-07-31 17:27:05 UTC
Severity:
normal
Tags:
#1042755#5
Date:
2023-07-31 11:27:35 UTC
From:
To:
Dear Maintainer,

Old issue, just annoyed with it enough now to post:
patch keeps reading when it got a zero-sized read,
and needs two subsequent zero-sized reads to actually apply the patch.

There's precisely no point to this (files and pipes always
keep returning empty), except to interfere with pasting diffs in because
you need to eof twice.

Just Don't Do It™ imo

Best,
наб

#1042755#16
Date:
2023-07-31 17:23:03 UTC
From:
To:
Trivially found with
(gdb) bt
#0  0x00007ffff7ec807d in __GI___libc_read (fd=0, buf=0x5555555862a0, nbytes=8192) at ../sysdeps/unix/sysv/linux/read.c:26
#1  0x00007ffff7e51130 in __GI__IO_file_xsgetn (fp=0x7ffff7fa2a80 <_IO_2_1_stdin_>, data=<optimized out>, n=8192) at ./libio/libioP.h:947
#2  0x00007ffff7e46625 in __GI__IO_fread (buf=0x5555555862a0, size=size@entry=1, count=8192, fp=fp@entry=0x7ffff7fa2a80 <_IO_2_1_stdin_>) at ./libio/iofread.c:38
#3  0x000055555555e2ec in fread (__stream=<optimized out>, __n=<optimized out>, __size=1, __ptr=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/stdio2.h:297
#4  open_patch_file (filename=<optimized out>) at pch.c:152
#5  0x0000555555558bcf in main (argc=<optimized out>, argv=<optimized out>) at patch.c:195

│      151          for (st.st_size = 0;
│  >   152               (charsread = fread (buf, 1, bufsize, read_pfp)) != 0;
│      153               st.st_size += charsread)
│      154            if (fwrite (buf, 1, charsread, pfp) != charsread)
│      155              write_fatal ();

which needs to check for !feof && (charsread = ....

Attaching patch against 2.7.6-7, validated it works.

Best,
наб