I've basically been converting line for line and adjusting where the Python libraries differ. However, I've encountered a problem with the way the CRCs are calculated for files, particularly those in zip files like tdm_update_win.zip.
When I converted the 'get_crc_for_file' function, I ended up with this:
overallcrc = 0 data = fh2.read(32768) while data: overallcrc ^= crc32(data) data = fh2.read(32768)
However, this would produce incorrect results for a number of files (negative values, which is clearly incorrect). The docs pointed at a better way of doing this, which fixed the problem, as shown below:
overallcrc = 0 data = fh2.read(32768) while data: overallcrc = crc32(data, overallcrc) & 0xffffffff data = fh2.read(32768)
But I was still having issues where my Python version was throwing up the updater executables as checksum mismatches. I installed HashTab (http://beeblebrox.org/) to compare my generated CRC32s to what HashTab says and what crc_info.txt says as well as the CRC32 shown by WinRAR for the archive. According to crc_info.txt:
[File tdm_update_win.zip]
crc = 7ca4ce95
size = 2763886
[Member tdm_update_win.zip:tdm_update.exe]
crc = 9850fccf
size = 4995906
Running my Python version:
python tdm_update.py --dry-run --verbose
[snip]
tdm_update.exe Info: tdm_update.exe is inside tdm_update_win.zip
CRC for local file: 7ca4ce95, CRC on server is 9850fccf
checksum mismatch, getting tdm_update_win.zip.
HashTab and WinRAR both report the CRC32 for tdm_update.exe as: 7CA4CE95
So I looked at the Perl version of 'get_crc_for_file' and converted it from:
my $overallcrc = 0;
while (($n = read $fh2, $data, 32768) != 0)
{
$overallcrc ^= Archive::Zip::computeCRC32($data);
}
To:
my $overallcrc = 0;
while (($n = read $fh2, $data, 32768) != 0)
{
$overallcrc = Archive::Zip::computeCRC32($data, $overallcrc);
}
And that code now produces 7ca4ce95 as the CRC32 for tdm_update.exe instead of 9850fccf. You can actually see that there is a problem with the existing code by looking at the crc_info.txt file. The CRC for a zip file is calculated by XORing the CRCs for each file in the archive. And since the the updater zip only has 1 file and the CRC used in this case is taken from the zip archive and not calculated, the File entry should have the same CRC as the Member entry. This needs to be fixed for the current tdm_update.pl as well as the deployment scripts such as calculate_crcs.pl.

Sign In
Register
Help
MultiQuote




