Subject: | siphash32 leaks |
siphash32 leaks two scalars per call:
$ perl -MDigest::SipHash=siphash32 -MTest::LeakTrace -lwe 'no_leaks_ok { siphash32("ololo", 8x16) };'
not ok 1 - leaks 2 <= 0
# Failed test 'leaks 2 <= 0'
# at -e line 1.
# '2'
# <=
# '0'
# leaked SCALAR(0x1f2bd90) from /usr/lib64/perl5/vendor_perl/Digest/SipHash.pm line 26.
# 25: $seed .= substr( $DEFAULT_SEED, length($seed) ) if length($seed) < 16;
# 26: my $lohi = _xs_siphash_av( $str, $seed );
# 27: return wantarray ? @$lohi : $lohi->[0];
# SV = IV(0x1f2bd88) at 0x1f2bd90
# REFCNT = 1
# FLAGS = (IOK,pIOK)
# IV = 2051427313
# leaked SCALAR(0x1f2bd48) from /usr/lib64/perl5/vendor_perl/Digest/SipHash.pm line 26.
# 25: $seed .= substr( $DEFAULT_SEED, length($seed) ) if length($seed) < 16;
# 26: my $lohi = _xs_siphash_av( $str, $seed );
# 27: return wantarray ? @$lohi : $lohi->[0];
# SV = IV(0x1f2bd40) at 0x1f2bd48
# REFCNT = 1
# FLAGS = (IOK,pIOK)
# IV = 1250098827
Patch from attachment helps to solve this leakage
Subject: | perl-Digest-SipHash-noleak.patch |
--- SipHash.xs 2016-03-04 15:44:11.175183854 +0300
+++ SipHash.xs 2016-03-04 15:44:11.175183854 +0300
@@ -9,13 +9,12 @@
static SV *
siphash_as_av(SV *src, SV *seed) {
- SV* retval;
- SV* sva[2];
uint64_t hash = siphash24(SvPV_nolen(src), SvCUR(src), SvPV_nolen(seed));
- sva[0] = newSVuv(hash & 0xffffffff);
- sva[1] = newSVuv(hash >> 32);
- retval = newRV_noinc((SV *)av_make(2, sva));
- return retval;
+ AV *av = newAV();
+ av_extend(av, 1);
+ av_store(av, 0, newSVuv(hash & 0xffffffff));
+ av_store(av, 1, newSVuv(hash >> 32));
+ return newRV_noinc((SV *)av);
}
MODULE = Digest::SipHash PACKAGE = Digest::SipHash