Package: coreutils
Version: 8.21-1.1
Followup-For: Bug #630944

Dear Maintainer,

I can reproduce this issue with version 8.21-1.1.
I have checked the source and I am proposing the attached patch.
I believe the problem only affect special files (size == 0) so
a special case is needed for that.


-- System Information:
Debian Release: jessie/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 3.13-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages coreutils depends on:
ii  libacl1      2.2.52-1
ii  libattr1     1:2.4.47-1
ii  libc6        2.18-4
ii  libselinux1  2.2.2-1

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information
diff --git a/src/dd.c b/src/dd.c
index c98e578..03b0c54 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1552,11 +1552,15 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize,
            struct stat st;
            if (fstat (STDIN_FILENO, &st) != 0)
              error (EXIT_FAILURE, errno, _("cannot fstat %s"), quote (file));
-           if (usable_st_size (&st) && st.st_size < input_offset + offset)
+           if (usable_st_size (&st) && st.st_size > 0 && st.st_size < input_offset + offset)
              {
-               /* When skipping past EOF, return the number of _full_ blocks
-                * that are not skipped, and set offset to EOF, so the caller
-                * can determine the requested skip was not satisfied.  */
+               /* For file with size > 0 (there's no way to tell the difference
+               * between a special file (really STDIN or something like
+               * /proc/self/mem) because the fdesc has been reopened as
+               * STDIN_FILENO)
+               * and when skipping past EOF, return the number of _full_ blocks
+               * that are not skipped, and set offset to EOF, so the caller
+               * can determine the requested skip was not satisfied.  */
                records = ( offset - st.st_size ) / blocksize;
                offset = st.st_size - input_offset;
              }

Reply via email to