Why does crc32 say some of my files are 'BAD'?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I used crc32
to compare some files with a backup of them. Out of 3556 files, 11 were reported as 'BAD' as in the following example:
9be46354 ./9836Feeding_the_dog_.mpeg BAD 9be46354 != 9836Feed
However, the files are not bad, but for some reason crc32
has compared the checksum it calculated with part of the filename.
I then tried an experiment:
$ echo 12345 > 9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
So this time crc32
appears not to have compared the checksum with the filename, and the file is not 'BAD'.
What is happening here? Does this happen to other checksums?
filenames checksum
add a comment |
up vote
2
down vote
favorite
I used crc32
to compare some files with a backup of them. Out of 3556 files, 11 were reported as 'BAD' as in the following example:
9be46354 ./9836Feeding_the_dog_.mpeg BAD 9be46354 != 9836Feed
However, the files are not bad, but for some reason crc32
has compared the checksum it calculated with part of the filename.
I then tried an experiment:
$ echo 12345 > 9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
So this time crc32
appears not to have compared the checksum with the filename, and the file is not 'BAD'.
What is happening here? Does this happen to other checksums?
filenames checksum
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I used crc32
to compare some files with a backup of them. Out of 3556 files, 11 were reported as 'BAD' as in the following example:
9be46354 ./9836Feeding_the_dog_.mpeg BAD 9be46354 != 9836Feed
However, the files are not bad, but for some reason crc32
has compared the checksum it calculated with part of the filename.
I then tried an experiment:
$ echo 12345 > 9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
So this time crc32
appears not to have compared the checksum with the filename, and the file is not 'BAD'.
What is happening here? Does this happen to other checksums?
filenames checksum
I used crc32
to compare some files with a backup of them. Out of 3556 files, 11 were reported as 'BAD' as in the following example:
9be46354 ./9836Feeding_the_dog_.mpeg BAD 9be46354 != 9836Feed
However, the files are not bad, but for some reason crc32
has compared the checksum it calculated with part of the filename.
I then tried an experiment:
$ echo 12345 > 9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
So this time crc32
appears not to have compared the checksum with the filename, and the file is not 'BAD'.
What is happening here? Does this happen to other checksums?
filenames checksum
filenames checksum
edited 1 hour ago
Filipe Brandenburger
5,3791624
5,3791624
asked 5 hours ago
EmmaV
1,0291229
1,0291229
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The crc32
executable that you are using is a Perl script distributed together with the Archive::Zip
Perl module.
The crc32
Perl script is quite short, and has this little thing in it:
if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]8)[^[:xdigit:]]/ )
my $filenameCrc = $1;
if ( lc($filenameCrc) eq lc($fileCrc) )
print("tOK")
else
print("tBAD $fileCrc != $filenameCrc");
That is, if the pathname of the file contains eight consecutive hexadecimal digits, preceded and followed by at least one non-hexadecimal digit, this hexadecimal number is compared with the CRC32 checksum of the file.
In your case, you're running crc32
on ./9836Feeding_the_dog_.mpeg
. This pathname contains some non-hexadecimal digits (./
) followed by exactly eight hexadecimal digits (9836Feed
) and then something non-hexadecimal again. 9836Feed
is not the CRC32 checksum of the file, so it complains.
Example that triggers this behaviour that is "not BAD":
$ cat 261dafe6_file
12345
$ crc32 ./261dafe6_file
261dafe6 OK
Recreating your test, and provoking the "BAD" response by adding ./
in front of the pathname of the file:
$ echo 12345 >9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
$ crc32 ./9836Feeding_the_dog_.mpeg
261dafe6 BAD 261dafe6 != 9836Feed
Since the crc32
executable is undocumented, obviously somewhat quirky, and not widely used (I didn't know about it and had to track it down, but that may not say much) I would suggest using some other tool for calculating the checksums of files. The md5sum
tool from GNU coreutils is widely used, and on BSD systems you may use md5
. There are also utilities for calculating stronger hashes (SHA1, SHA256 and SHA512 and others are supported by readily available utilities).
(By "non-hexadecimal digit" I mean "something that is not a hexadecimal digit")
Thanks. Please can you explain whycrc32 ./9836Feeding_the_dog_.mpeg
results inBAD...
butcrc32 9836Feeding_the_dog_.mpeg
doesn't?
– EmmaV
5 hours ago
1
@EmmaV The code ofcrc32
takes the./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.
– Kusalananda
5 hours ago
1
I'll change tomd5sum
.
– EmmaV
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The crc32
executable that you are using is a Perl script distributed together with the Archive::Zip
Perl module.
The crc32
Perl script is quite short, and has this little thing in it:
if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]8)[^[:xdigit:]]/ )
my $filenameCrc = $1;
if ( lc($filenameCrc) eq lc($fileCrc) )
print("tOK")
else
print("tBAD $fileCrc != $filenameCrc");
That is, if the pathname of the file contains eight consecutive hexadecimal digits, preceded and followed by at least one non-hexadecimal digit, this hexadecimal number is compared with the CRC32 checksum of the file.
In your case, you're running crc32
on ./9836Feeding_the_dog_.mpeg
. This pathname contains some non-hexadecimal digits (./
) followed by exactly eight hexadecimal digits (9836Feed
) and then something non-hexadecimal again. 9836Feed
is not the CRC32 checksum of the file, so it complains.
Example that triggers this behaviour that is "not BAD":
$ cat 261dafe6_file
12345
$ crc32 ./261dafe6_file
261dafe6 OK
Recreating your test, and provoking the "BAD" response by adding ./
in front of the pathname of the file:
$ echo 12345 >9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
$ crc32 ./9836Feeding_the_dog_.mpeg
261dafe6 BAD 261dafe6 != 9836Feed
Since the crc32
executable is undocumented, obviously somewhat quirky, and not widely used (I didn't know about it and had to track it down, but that may not say much) I would suggest using some other tool for calculating the checksums of files. The md5sum
tool from GNU coreutils is widely used, and on BSD systems you may use md5
. There are also utilities for calculating stronger hashes (SHA1, SHA256 and SHA512 and others are supported by readily available utilities).
(By "non-hexadecimal digit" I mean "something that is not a hexadecimal digit")
Thanks. Please can you explain whycrc32 ./9836Feeding_the_dog_.mpeg
results inBAD...
butcrc32 9836Feeding_the_dog_.mpeg
doesn't?
– EmmaV
5 hours ago
1
@EmmaV The code ofcrc32
takes the./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.
– Kusalananda
5 hours ago
1
I'll change tomd5sum
.
– EmmaV
4 hours ago
add a comment |
up vote
2
down vote
accepted
The crc32
executable that you are using is a Perl script distributed together with the Archive::Zip
Perl module.
The crc32
Perl script is quite short, and has this little thing in it:
if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]8)[^[:xdigit:]]/ )
my $filenameCrc = $1;
if ( lc($filenameCrc) eq lc($fileCrc) )
print("tOK")
else
print("tBAD $fileCrc != $filenameCrc");
That is, if the pathname of the file contains eight consecutive hexadecimal digits, preceded and followed by at least one non-hexadecimal digit, this hexadecimal number is compared with the CRC32 checksum of the file.
In your case, you're running crc32
on ./9836Feeding_the_dog_.mpeg
. This pathname contains some non-hexadecimal digits (./
) followed by exactly eight hexadecimal digits (9836Feed
) and then something non-hexadecimal again. 9836Feed
is not the CRC32 checksum of the file, so it complains.
Example that triggers this behaviour that is "not BAD":
$ cat 261dafe6_file
12345
$ crc32 ./261dafe6_file
261dafe6 OK
Recreating your test, and provoking the "BAD" response by adding ./
in front of the pathname of the file:
$ echo 12345 >9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
$ crc32 ./9836Feeding_the_dog_.mpeg
261dafe6 BAD 261dafe6 != 9836Feed
Since the crc32
executable is undocumented, obviously somewhat quirky, and not widely used (I didn't know about it and had to track it down, but that may not say much) I would suggest using some other tool for calculating the checksums of files. The md5sum
tool from GNU coreutils is widely used, and on BSD systems you may use md5
. There are also utilities for calculating stronger hashes (SHA1, SHA256 and SHA512 and others are supported by readily available utilities).
(By "non-hexadecimal digit" I mean "something that is not a hexadecimal digit")
Thanks. Please can you explain whycrc32 ./9836Feeding_the_dog_.mpeg
results inBAD...
butcrc32 9836Feeding_the_dog_.mpeg
doesn't?
– EmmaV
5 hours ago
1
@EmmaV The code ofcrc32
takes the./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.
– Kusalananda
5 hours ago
1
I'll change tomd5sum
.
– EmmaV
4 hours ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The crc32
executable that you are using is a Perl script distributed together with the Archive::Zip
Perl module.
The crc32
Perl script is quite short, and has this little thing in it:
if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]8)[^[:xdigit:]]/ )
my $filenameCrc = $1;
if ( lc($filenameCrc) eq lc($fileCrc) )
print("tOK")
else
print("tBAD $fileCrc != $filenameCrc");
That is, if the pathname of the file contains eight consecutive hexadecimal digits, preceded and followed by at least one non-hexadecimal digit, this hexadecimal number is compared with the CRC32 checksum of the file.
In your case, you're running crc32
on ./9836Feeding_the_dog_.mpeg
. This pathname contains some non-hexadecimal digits (./
) followed by exactly eight hexadecimal digits (9836Feed
) and then something non-hexadecimal again. 9836Feed
is not the CRC32 checksum of the file, so it complains.
Example that triggers this behaviour that is "not BAD":
$ cat 261dafe6_file
12345
$ crc32 ./261dafe6_file
261dafe6 OK
Recreating your test, and provoking the "BAD" response by adding ./
in front of the pathname of the file:
$ echo 12345 >9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
$ crc32 ./9836Feeding_the_dog_.mpeg
261dafe6 BAD 261dafe6 != 9836Feed
Since the crc32
executable is undocumented, obviously somewhat quirky, and not widely used (I didn't know about it and had to track it down, but that may not say much) I would suggest using some other tool for calculating the checksums of files. The md5sum
tool from GNU coreutils is widely used, and on BSD systems you may use md5
. There are also utilities for calculating stronger hashes (SHA1, SHA256 and SHA512 and others are supported by readily available utilities).
(By "non-hexadecimal digit" I mean "something that is not a hexadecimal digit")
The crc32
executable that you are using is a Perl script distributed together with the Archive::Zip
Perl module.
The crc32
Perl script is quite short, and has this little thing in it:
if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]8)[^[:xdigit:]]/ )
my $filenameCrc = $1;
if ( lc($filenameCrc) eq lc($fileCrc) )
print("tOK")
else
print("tBAD $fileCrc != $filenameCrc");
That is, if the pathname of the file contains eight consecutive hexadecimal digits, preceded and followed by at least one non-hexadecimal digit, this hexadecimal number is compared with the CRC32 checksum of the file.
In your case, you're running crc32
on ./9836Feeding_the_dog_.mpeg
. This pathname contains some non-hexadecimal digits (./
) followed by exactly eight hexadecimal digits (9836Feed
) and then something non-hexadecimal again. 9836Feed
is not the CRC32 checksum of the file, so it complains.
Example that triggers this behaviour that is "not BAD":
$ cat 261dafe6_file
12345
$ crc32 ./261dafe6_file
261dafe6 OK
Recreating your test, and provoking the "BAD" response by adding ./
in front of the pathname of the file:
$ echo 12345 >9836Feeding_the_dog_.mpeg
$ crc32 9836Feeding_the_dog_.mpeg
261dafe6
$ crc32 ./9836Feeding_the_dog_.mpeg
261dafe6 BAD 261dafe6 != 9836Feed
Since the crc32
executable is undocumented, obviously somewhat quirky, and not widely used (I didn't know about it and had to track it down, but that may not say much) I would suggest using some other tool for calculating the checksums of files. The md5sum
tool from GNU coreutils is widely used, and on BSD systems you may use md5
. There are also utilities for calculating stronger hashes (SHA1, SHA256 and SHA512 and others are supported by readily available utilities).
(By "non-hexadecimal digit" I mean "something that is not a hexadecimal digit")
edited 5 hours ago
answered 5 hours ago
Kusalananda
114k15218349
114k15218349
Thanks. Please can you explain whycrc32 ./9836Feeding_the_dog_.mpeg
results inBAD...
butcrc32 9836Feeding_the_dog_.mpeg
doesn't?
– EmmaV
5 hours ago
1
@EmmaV The code ofcrc32
takes the./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.
– Kusalananda
5 hours ago
1
I'll change tomd5sum
.
– EmmaV
4 hours ago
add a comment |
Thanks. Please can you explain whycrc32 ./9836Feeding_the_dog_.mpeg
results inBAD...
butcrc32 9836Feeding_the_dog_.mpeg
doesn't?
– EmmaV
5 hours ago
1
@EmmaV The code ofcrc32
takes the./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.
– Kusalananda
5 hours ago
1
I'll change tomd5sum
.
– EmmaV
4 hours ago
Thanks. Please can you explain why
crc32 ./9836Feeding_the_dog_.mpeg
results in BAD...
but crc32 9836Feeding_the_dog_.mpeg
doesn't?– EmmaV
5 hours ago
Thanks. Please can you explain why
crc32 ./9836Feeding_the_dog_.mpeg
results in BAD...
but crc32 9836Feeding_the_dog_.mpeg
doesn't?– EmmaV
5 hours ago
1
1
@EmmaV The code of
crc32
takes the ./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without ./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.– Kusalananda
5 hours ago
@EmmaV The code of
crc32
takes the ./
at the start of the filename into account when finding the hexadecimal number in the in the filename. Without ./
, the regular expression does not match (since the 8-digit hex number is then not preceded by a non-hex digit) so that piece of the code that I quoted is not triggered. It's silly, really. Use another tool if you're able to.– Kusalananda
5 hours ago
1
1
I'll change to
md5sum
.– EmmaV
4 hours ago
I'll change to
md5sum
.– EmmaV
4 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481141%2fwhy-does-crc32-say-some-of-my-files-are-bad%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password