Hello,

the percentage value reported by scp 1.2.26 as part of the statistics
display is incorrectly calculated when transferring large files (650 MB in my
case) from a remote server to the local machine.

If this is old news please ignore my message. Otherwise I suggest to fix it in
SSH 1.2.27 if this release should ever appear :-)

The percentage is calculated in two functions:

 - in source(), when the local scp process is sending data,
 
 - and in sink(), when the local scp process is receiving data. 

In source() the calculation is correct:

     840  fprintf(SOME_STATS_FILE,
     841      "\r%-25.25s | %10ld KB | %5.1f kB/s | ETA: %s | %3d%%",
     842      last,
     843      statbytes / 1024,
     844      ratebs / 1024,
     845      stat_eta((int) ((stb.st_size
     846               - statbytes)
     847              / ratebs)),
-->  848      (int) (100.0 *
-->  849         (double) statbytes /
-->  850         stb.st_size));

But in sink() it's wrong because of an integer overflow:


    1145  fprintf(SOME_STATS_FILE,
    1146      "\r%-25.25s | %10ld KB | %5.1f kB/s | ETA: %s | %3d%%",
    1147      statslast,
    1148      statbytes / 1024,
    1149      ratebs / 1024,
    1150      stat_eta((int)
    1151           ((size - statbytes)
    1152            / ratebs)),
--> 1153      100 * statbytes / size);
    
The solution is simple, of course. The value must be calculated as double
and be converted back to int before printing it:

   1153      (int) (100.0 * (double) statbytes / size));



Holger

Reply via email to