Hi Paolo

On Wed, Aug 08, 2007 at 01:59:46PM -0400, Paolo Benvenuto wrote:
> Package: cron-apt
> Version: 0.6.0
> Severity: normal
> 
> I have block size of 4096, and the calculation of tmpdir size overflows, 
> giving a negative value
> 
>     if [ "$(( $(stat --file-system --format=%S $TMPDIR) * $(stat 
> --file-system --format=%a $TMPDIR) / 1024 ))" -lt "$MINTMPDIRSIZE" ];
> 
> the 1st. element, stat --format=%S, gives 4096, the 2nd, stat --format=%S, 
> gives 1963117, the product gives -549019648 !
> 
> So cron-apt is unusable: never runs because of this incorrect calculation of 
> disk space.

Not good! Do you know where the limit of the overflow is? I think it is
a 32 bit integer that is used.

1963117*4096=8040927232
2^32=4294967296
2^32*2=8589934592
8040927232-8589934592=-549007360 which is in the same magnitude at least.

A way is to calculate in a different way to avoid the overflow. For example
divide by 1024 before the multiplication. However when I try this on my
own system the calculation is correct:

echo $((1963117*4096/1024))
7852468

But with dash...

$ echo $((1963117*4096/1024))
-536140

[EMAIL PROTECTED]:~$ dash
$ echo $((4096/1024*1963117))
7852468

However the sector size can be 512 so the formula need to be
$((X/512*Y/2))

And then a check on Y > 

The maximum sector size of xfs is 32768, which means 32768/512=2^6.
This means that if Y >= 33554432 then we can have an overflow
in the calculation if using the new formula.

If you change the function to the code below do it work for you then?


# Check the tmpdir size and exit if the space is too small.
checktmpsize() {
    # Sector size
        SSIZE=$(stat --file-system --format=%S $TMPDIR)
    # Number of free sectors
    FSCOUNT=$(stat --file-system --format=%a $TMPDIR)
    # Check to  avoid overflow in calculations when using dash 2^(32-1-6)
    # The number        size above is   got from 32768/512=2^6
    if [ "$FSCOUNT" -lt 33554432 ] ; then
        if [ "$(($SSIZE / 512 * $FSCOUNT / 2))" -lt "$MINTMPDIRSIZE" ]; then
        echo >&2 "Error: Not enough free space in $TMPDIR."
            exit 1
                fi
    fi
}

If it do, I'll update the package straight away.

Regards,

// Ola



> Debian Release: lenny/sid
>   APT prefers unstable
>   APT policy: (990, 'unstable'), (500, 'testing')
> Architecture: i386 (i686)
> 
> Kernel: Linux 2.6.22-1-686 (SMP w/1 CPU core)
> Locale: LANG=es_DO.UTF-8, LC_CTYPE=es_DO.UTF-8 (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> 
> Versions of packages cron-apt depends on:
> ii  apt                           0.7.6      Advanced front-end for dpkg
> ii  debianutils                   2.23.1     Miscellaneous utilities specific 
> t
> 
> Versions of packages cron-apt recommends:
> ii  cron             3.0pl1-100              management of regular background 
> p
> ii  liblockfile1     1.06.2                  NFS-safe locking library, 
> includes
> ii  mailx            1:8.1.2-0.20070424cvs-1 A simple mail user agent
> 
> -- no debconf information
> 
> 

-- 
 --------------------- Ola Lundqvist ---------------------------
/  [EMAIL PROTECTED]                     Annebergsslingan 37      \
|  [EMAIL PROTECTED]                     654 65 KARLSTAD          |
|  http://opalsys.net/                 +46 (0)70-332 1551       |
\  gpg/f.p.: 7090 A92B 18FE 7994 0C36  4FE4 18A1 B1CF 0FE5 3DD9 /
 ---------------------------------------------------------------


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to