BackupPC-users

Re: [BackupPC-users] Cross-platform bug/inconsistency in rsync digests (File::RsyncP::digest) - PROBLEM IS IN ADLER32!!!

2011-02-09 01:52:18
Subject: Re: [BackupPC-users] Cross-platform bug/inconsistency in rsync digests (File::RsyncP::digest) - PROBLEM IS IN ADLER32!!!
From: Craig Barratt <cbarratt AT users.sourceforge DOT net>
To: "Jeffrey J. Kosowsky" <backuppc AT kosowsky DOT org>
Date: Tue, 8 Feb 2011 22:50:31 -0800
Jeffrey writes:

> OK - I just spent the evening taking apart the rsync checksum stuff.
> The problem is in the Block Digests, not the File Digests.
> And the problem is actually in the Adler32 sum part and *not* in the
> md4sum.
> 
> However, I'm not sure what is causing the problem there...
> At first I thought it might be an Endian issue but from googling it
> seems that Linux is little endian on both x86 and armel.
> 
> Any ideas on what might be wrong and how to fix it?

Unfortunately this is a bug inherited from an earlier version of
rsync. The C language char data type can be signed or unsigned -
it is implementation dependent.  On ARM it is unsigned, and on x86
it is signed.

If you look in get_checksum1() from checksum.c in a recent rsync
you will see it typecasts buf to be signed char*.  I've edited
the code below with the fix (change buf to buf1 in the function
declaration and add a new declaration for buf):

Craig

> /*
>  * a simple 32 bit checksum that can be updated from either end
>  * (inspired by Mark Adler's Adler-32 checksum)
>  */
> UINT4 adler32_checksum(char *buf1, int len)
> {
>     int i;
>     UINT4 s1, s2;
>     signed char *buf = (signed char*)buf1;
> 
>     s1 = s2 = 0;
>     for ( i = 0 ; i < len - 4; i += 4 ) {
>         s2 += 4 * (s1 + buf[i]) + 3 * buf[i+1] + 2 * buf[i+2] + buf[i+3];
>         s1 += (buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3];
>     }
>     for ( ; i < len ; i++ ) {
>         s1 += buf[i];
>               s2 += s1;
>     }
>     return (s1 & 0xffff) + (s2 << 16);
> }

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/