Why does crc32 say some of my files are 'BAD'?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question



























    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?










    share|improve this question

























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      Filipe Brandenburger

      5,3791624




      5,3791624










      asked 5 hours ago









      EmmaV

      1,0291229




      1,0291229




















          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")






          share|improve this answer






















          • 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




            @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




            I'll change to md5sum.
            – EmmaV
            4 hours ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          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")






          share|improve this answer






















          • 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




            @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




            I'll change to md5sum.
            – EmmaV
            4 hours ago














          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")






          share|improve this answer






















          • 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




            @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




            I'll change to md5sum.
            – EmmaV
            4 hours ago












          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")






          share|improve this answer














          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")







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 5 hours ago









          Kusalananda

          114k15218349




          114k15218349











          • 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




            @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




            I'll change to md5sum.
            – 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







          • 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







          • 1




            I'll change to md5sum.
            – 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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?