Hack Kampbj�rn <[EMAIL PROTECTED]> writes:

>> assertion "percentage <= 100" failed: file "progress.c", line 552
>> zsh: abort (core dumped)  wget -m -c --tries=0
>> ftp://ftp.scene.org/pub/music/artists/nutcase/mp3/timeofourlives.mp3
>
> progress.c
>       int percentage = (int)(100.0 * size / bp->total_length);
>
>       assert (percentage <= 100);
> Of course the assert will fail, size is bigger than total_length !
[...]
> To reproduce with wget-1.8.1
> $ wget ftp://sunsite.dk/disk1/gnu/wget/wget-1.8{,.1}.tar.gz
> $ cat wget-1.8.tar.gz >> wget-1.8.1.tar.gz
> $ wget -d -c ftp://sunsite.dk/disk1/gnu/wget/wget-1.8.1.tar.gz

Thanks for looking into this.  There are two problems here, and most
likely two separate bugs.

First, I cannot repeat your test case.  Maybe sunsite.dk changed their
FTP server since Feb 15; anyway, what I get is:

--> REST 2185627

350 Restarting at 2185627
--> RETR wget-1.8.1.tar.gz

451-Restart offset 2185627 is too large for file size 1097780.
451 Restart offset reset to 0

Wget (bogusly) considers the 451 response to be "error in server
response" and retries.  That's bug number one, but it also means that
I cannot repeat your test case.


Bug number two is the one the reporter saw.  At first I didn't quite
understand how it can happen, since bar_update() explicitly guards
against such a condition:

  if (bp->total_length > 0
      && bp->count + bp->initial_length > bp->total_length)
    /* We could be downloading more than total_length, e.g. when the
       server sends an incorrect Content-Length header.  In that case,
       adjust bp->total_length to the new reality, so that the code in
       create_image() that depends on total size being smaller or
       equal to the expected size doesn't abort.  */
    bp->total_length = bp->count + bp->initial_length;

The problem is that the same guard is not implemented in bar_create()
and bar_finish(), which also call create_image().  In the FTP case,
the crash comes from bar_create.  This patch should fix it.

2002-04-11  Hrvoje Niksic  <[EMAIL PROTECTED]>

        * progress.c (bar_create): If INITIAL is larger than TOTAL, fix
        TOTAL.
        (bar_finish): Likewise.

Index: src/progress.c
===================================================================
RCS file: /pack/anoncvs/wget/src/progress.c,v
retrieving revision 1.27
diff -u -r1.27 progress.c
--- src/progress.c      2002/04/11 17:49:32     1.27
+++ src/progress.c      2002/04/11 18:49:08
@@ -461,6 +461,11 @@
 
   memset (bp, 0, sizeof (*bp));
 
+  /* In theory, our callers should take care of this pathological
+     case, but it can sometimes happen. */
+  if (initial > total)
+    total = initial;
+
   bp->initial_length = initial;
   bp->total_length   = total;
 
@@ -493,7 +498,7 @@
        adjust bp->total_length to the new reality, so that the code in
        create_image() that depends on total size being smaller or
        equal to the expected size doesn't abort.  */
-    bp->total_length = bp->count + bp->initial_length;
+    bp->total_length = bp->initial_length + bp->count;
 
   /* This code attempts to determine the current download speed.  We
      measure the speed over the interval of approximately three
@@ -564,6 +569,11 @@
 bar_finish (void *progress, long dltime)
 {
   struct bar_progress *bp = progress;
+
+  if (bp->total_length > 0
+      && bp->count + bp->initial_length > bp->total_length)
+    /* See bar_update() for explanation. */
+    bp->total_length = bp->initial_length + bp->count;
 
   create_image (bp, dltime);
   display_image (bp->buffer);

Reply via email to