GNU bug report logs - #18621
[BUG] wc -c incorrectly counts bytes in /sys

Previous Next

Package: coreutils;

Reported by: George Shuklin <george.shuklin <at> gmail.com>

Date: Fri, 3 Oct 2014 15:13:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jim Meyering <jim <at> meyering.net>, Pádraig Brady <P <at> draigbrady.com>
Cc: 18621 <at> debbugs.gnu.org, George Shuklin <george.shuklin <at> gmail.com>
Subject: bug#18621: [BUG] wc -c incorrectly counts bytes in /sys
Date: Fri, 03 Oct 2014 11:47:49 -0700
On 10/03/2014 11:26 AM, Jim Meyering wrote:
> That looks like a fine fix.

Unfortunately that fix would make 'wc -c' waaaaay slower for a file that 
consists entirely of a big hole.

How about if we change usable_st_size to return false for these proc 
files, with a heuristic as tight as we can make it, and to have 
coreutils check usable_st_size in more places.  Something like this, 
perhaps:

  /* Return a boolean indicating whether SB->st_size is correct. */
  static inline bool
  usable_st_size (struct stat const *sb)
  {
    if (S_ISREG (sb->st_mode))
      {
        /* proc files like /sys/kernel/vmcoreinfo are weird: their
           st_size values do not reflect what's actually in them.
           The following heuristic attempts to catch proc files without
           catching many regular files that just happen to have the same
           signature.  */
        return ! (sb->st_uid == 0 && sb->st_gid == 0 && sb->st_blocks == 0
                  && sb->st_size == ST_BLKSIZE (*sb));
      }
    return (S_ISLNK (sb->st_mode) || S_TYPEISSHM (sb) || S_TYPEISTMO (sb));
  }


and then review every place where coreutils currently uses st_size and 
prepend a check for usable_st_size if needed.




This bug report was last modified 10 years and 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.