Control: tags -1 + patch
Control: forwarded -1 https://github.com/htop-dev/htop/pull/1351

On Sat, Dec 23, 2023 at 08:52:11PM +0100, roz@rozbrajacz.futbol wrote:
> Package: htop
> Version: 3.2.2-2
> Severity: normal
> 
> I see
>   Snapshot of files open in process 3291819 - qemu-img convert -f vmdk -O 
> qcow2 WinDev2311Eval-disk001.vmdk WinDev2311E...
>      FD TYPE    MODE DEVICE           SIZE     OFFSET       NODE  NAME
>       0 CHR     u    0x17                0          0          7  /dev/pts/4
>       1 CHR     u    0x17                0          0          7  /dev/pts/4
>       2 CHR     u    0x17                0          0          7  /dev/pts/4
>       3 a_inode u    0xe                            0       2075  [signalfd]
>       4 REG     r    0x55       2299244800 0x55a74ea0      15530  
> /mnt/filling/store/user2/WinDev2311Eval-disk001.vmdk
>       5 a_inode u    0xe                            0       2075  [eventfd:26]
>       6 a_inode u    0xe                            0       2075  [eventfd:28]
>       7 a_inode u    0xe                            0       2075  [eventfd:27]
>       8 REG     u    0x55       2580558643     198608       4170  
> /mnt/filling/store/user2/WinDev2311Eval-disk001.qcow2
>     cwd DIR          0x55               46                    34  
> /mnt/filling/store/user2
> but
>   $ ls -lh WinDev2311Eval-disk001.*
>   -rw-r--r-- 1 user2 users 28G Dec 23 20:50 WinDev2311Eval-disk001.qcow2
>   -rw-r----- 1 user2 users 22G Nov 15 04:34 WinDev2311Eval-disk001.vmdk
> 
> This clearly displays the bottom four bytes of the 8-byte off_t.
Shockingly, I don't think it does, this is actually much worse.

OpenFilesScreen.c sayeth:
  226       struct stat st;
  227       if (stat(filename, &st) == 0) {
  228          char fileSizeBuf[21]; /* 20 (long long) + 1 (NULL) */
  229          xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, 
(uint64_t)st.st_size); /* st.st_size is long long on macOS, long on linux */
  230          free_and_xStrdup(&item->data[fileSizeIndex], fileSizeBuf);
  231       }
and tracing confirms it's correct. Indeed, both the number and the
string are 23622320128 for a 22G file. But the displayed
string is  2362232012.

Y'know. Like it's truncated by a digit. Indeed,
      4 REG     r    0x71       2362232012          0   10840201  
/home/nabijaczleweli/uwu/htop/22G
      5 REG     w    0x71              546          0   10840820  
/home/nabijaczleweli/uwu/htop/log
      6 REG     r    0x71       2362232012          0   10840828  
/home/nabijaczleweli/uwu/htop/220G
      7 REG     r    0x71       2362232012          0   10840829  
/home/nabijaczleweli/uwu/htop/2200G
      8 REG     r    0x71       2362232012          0   10840830  
/home/nabijaczleweli/uwu/htop/22000G
only the first ten digits are shown in either case.
There's space for like 17 without widening the hole!

Indeed, it looks like for some reason with the format being (spaces
substituted) "%5.5sQ%-7.7sW%-4.4sE%-10.10sR%10.10sT%10.10sY%10.10s  %s")
the device hole is a full 10 bytes:
     FD TYPE    MODE DEVICE           SIZE     OFFSET       NODE  NAME
      8QREG    Wr   E0x71      R2362232012T         0Y  10840830  
/home/nabijaczleweli/uwu/htop/22000G

The diff below can be applied to instead produce correct results for up
to single-digit-petabyte files:
  Snapshot of files open in process 66238 - htop│./htop
     FD TYPE    MODE DEVICE           SIZE     OFFSET       NODE  NAME
      0 CHR     u    0x17                0          0          9  /dev/pts/6
      1 CHR     u    0x17                0          0          9  /dev/pts/6
      2 CHR     u    0x17                0          0          9  /dev/pts/6
      3 FIFO    r    0xd                            0  875953773  pipe
      4 REG     r    0x71      23622320128          0   10840201  
/home/nabijaczleweli/uwu/htop/22G
      5 REG     w    0x71                0          0   10840820  
/home/nabijaczleweli/uwu/htop/log
      6 REG     r    0x71     236223201280          0   10840828  
/home/nabijaczleweli/uwu/htop/220G
      7 REG     r    0x71    2362232012800          0   10840829  
/home/nabijaczleweli/uwu/htop/2200G
      8 REG     r    0x71   23622320128000          0   10840830  
/home/nabijaczleweli/uwu/htop/22000G
      9 REG     r    0x71  236223201280000          0   10840846  
/home/nabijaczleweli/uwu/htop/220000G
     10 REG     r    0x71 2362232012800000          0   10840847  
/home/nabijaczleweli/uwu/htop/2200000G
    cwd DIR          0x71             5220              10839773  
/home/nabijaczleweli/uwu/htop
    mem REG          0x22            27028                614730  
/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
    mem REG          0x22            47288                334232  
/usr/lib/x86_64-linux-gnu/libcap.so.2.66
    mem REG          0x22           210968                613682  
/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    mem REG          0x22           216368                440144  
/usr/lib/x86_64-linux-gnu/libtinfo.so.6.4
    mem REG          0x22           231344                462346  
/usr/lib/x86_64-linux-gnu/libncursesw.so.6.4
    mem REG          0x22           325896                634016  
/usr/lib/x86_64-linux-gnu/libnss_systemd.so.2
    mem REG          0x22           907784                613694  
/usr/lib/x86_64-linux-gnu/libm.so.6
    mem REG          0x22          1922136                613688  
/usr/lib/x86_64-linux-gnu/libc.so.6
    mem REG          0x22          8547984                609660  
/usr/lib/locale/locale-archive
    rtd DIR          0x20               30                    34  /
    txt REG          0x71          1324944              10840859  
/home/nabijaczleweli/uwu/htop/htop

Best,
наб
-- 
diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c
index 3077490..03260bf 100644
--- a/OpenFilesScreen.c
+++ b/OpenFilesScreen.c
@@ -253,7 +253,7 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
       while (fdata) {
          OpenFiles_Data* data = &fdata->data;
          char* entry = NULL;
-         xAsprintf(&entry, "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s 
%10.10s  %s",
+         xAsprintf(&entry, "%5.5s %-7.7s %-4.4s %-4.4s %16.16s %10.10s %10.10s 
 %s",
                    getDataForType(data, 'f'),
                    getDataForType(data, 't'),
                    getDataForType(data, 'a'),

Attachment: signature.asc
Description: PGP signature

Reply via email to