grondilu / libdigest-raku

Raku implementation of various digests
Artistic License 2.0
27 stars 42 forks source link

md5() crashes with Cannot unbox negative bigint... #33

Closed pheix closed 1 year ago

pheix commented 1 year ago

Looks like smth was broken with https://github.com/grondilu/libdigest-raku/commit/289a042ec2e7e556dc73780b58ed99362055de77:

Digest:ver<0.8.2>:auth<Lucien Grondin>
[kostas@webtech-omen core-perl6]$ zef install "Digest:ver<0.8.2>"
===> Searching for: Digest:ver<0.8.2>
===> Testing: Digest:ver<0.8.2>
===> Testing [OK] for Digest:ver<0.8.2>
===> Installing: Digest:ver<0.8.2>
[kostas@webtech-omen core-perl6]$ raku -MDigest -e "md5('158.389').say";
Blob:0x<1D 83 F5 B9 D9 6A F1 A2 5F 36 38 42 31 03 BE 1B>
[kostas@webtech-omen core-perl6]$ zef uninstall Digest
===> Uninstalled from inst#/opt/rakudo/rakudo-star-2022.04/share/perl6/site
Digest:ver<0.8.2>:auth<Lucien Grondin>

[kostas@webtech-omen core-perl6]$ zef install "Digest:ver<0.9.0>"
===> Searching for: Digest:ver<0.9.0>
===> Testing: Digest:ver<0.9.0>
===> Testing [OK] for Digest:ver<0.9.0>
===> Installing: Digest:ver<0.9.0>
[kostas@webtech-omen core-perl6]$ raku -MDigest -e "md5('158.389').say";
Cannot unbox negative bigint into native unsigned integer
  in sub infix:«<<<» at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/08D38337202051EEADB24BAFC11F43DA5C064BAA (Digest) line 6
  in sub md5-block at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/08D38337202051EEADB24BAFC11F43DA5C064BAA (Digest) line 35
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/08D38337202051EEADB24BAFC11F43DA5C064BAA (Digest) line 47
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/08D38337202051EEADB24BAFC11F43DA5C064BAA (Digest) line 43
  in block <unit> at -e line 1

Looks relevant to #27 and #28.

It crashes on latest version as well:

[kostas@webtech-omen core-perl6]$ zef install Digest
===> Searching for: Digest
===> Testing: Digest:ver<0.23.1>
===> Testing [OK] for Digest:ver<0.23.1>
===> Installing: Digest:ver<0.23.1>
[kostas@webtech-omen core-perl6]$ raku -MDigest::MD5 -e "md5('158.389').say";
Cannot unbox negative bigint into native unsigned integer
  in block  at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 15
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 10
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 4
  in block <unit> at -e line 1
grondilu commented 1 year ago

It crashes on latest version as well:

Indeed it does on my machine too. Not sure why the tests don't crash.

PS. Very weirdly, it works fine when adding an alphabetic prefix:

$ raku -MDigest::MD5 -e "md5('x158.389').say";
Blob:0x<4C 99 79 A4 E8 CE 77 81 A1 99 A3 65 E4 03 C2 98>
pheix commented 1 year ago

:crying_cat_face:

[kostas@webtech-omen utils]$ raku -MDigest::MD5 -e "md5('158.389x').say";
Blob:0x<6E 80 44 F2 2A 16 E8 1D AC 6C 76 4C A5 B4 81 59>
[kostas@webtech-omen utils]$ raku -MDigest::MD5 -e "md5('158x389').say";
Blob:0x<77 13 9D 7E D3 0D AD 17 3C 12 72 64 E3 3A 8E 59>
[kostas@webtech-omen utils]$ raku -MDigest::MD5 -e "md5('158,389').say";
Blob:0x<AE 65 F5 3E 1B 3B 9E B6 B8 69 08 CE 85 FC A9 DE>
[kostas@webtech-omen utils]$ raku -MDigest::MD5 -e "md5('158.389').say";
Cannot unbox negative bigint into native unsigned integer
  in block  at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 15
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 10
  in sub md5 at /opt/rakudo/rakudo-star-2022.04/share/perl6/site/sources/09B6112E2626A59F08A91D5D4762CC9F145C0515 (Digest::MD5) line 4
  in block <unit> at -e line 1
grondilu commented 1 year ago

I'll just add a mod 2**32 operation at the necessary step

pheix commented 1 year ago

:rocket: update, let me check on my test base...

UPD: Perfect:

[kostas@webtech-omen utils]$ zef install https://github.com/grondilu/libdigest-raku.git
===> Testing: Digest:ver<0.24.0>
===> Testing [OK] for Digest:ver<0.24.0>
===> Installing: Digest:ver<0.24.0>
[kostas@webtech-omen core-perl6]$ time raku -MDigest::MD5 -e "for (1..1000000) { md5((0..10000).rand.Str) }";

real    21m59.710s
user    21m53.113s
sys 0m1.368s