Subject: | SafeBrowsing3.pm bug |
Date: | Mon, 30 Nov 2015 13:55:21 +0100 |
To: | <julien [...] sobrier.net>, <bug-Net-Google-SafeBrowsing3 [...] rt.cpan.org> |
From: | "Jesper Knudsen" <jkn [...] swerts-knudsen.dk> |
Hi Julien,
I am a happy user of your perl contribution for GSB. I have found a bug that
you might want to update the package with. If you have any kind of
unpublished updates, then I am keen to test for you. I have a quite large
URL DB that I intended to take through this.
Rgds,
Jesper
In the function parse_full_hashes within SafeBrowsing3.pm, Google uses \r
(oxOA) rather than \n after "m" - goog-malware-shavar:32:2:m
This means the parsing needs to alter slightly:
if ($data =~ /^[a-z-]+:\d+:\d+(:m)?/gi) {
} else {
return ();
}
$data =~ s/^([a-z-]+)://;
my $list = $1;
$self->debug("List: ", $list, "\n");
$data =~ s/^(\d+)://;
my $length = $1;
$self->debug("Full hash length: ", $length, "\n");
$data =~ s/^(\d+)//;
my $num = $1;
$self->debug("Number of full hashes returned: ", $num, "\n");
my $metadata = 0;
if ($data =~ s/:m//) {
$metadata = 1;
}
# get rid of newline chars
$data =~ s/[\r\n]//;
Same goes for the metadata portion
if ($metadata) {
my $count = 0;
while ($data =~ s/(\d+)//) {
my $meta_length = $1;
# get rid of newline chars
$data =~ s/[\r\n]//;
my $info = substr($data, 0, $meta_length, '');
$self->debug("Metadata: ",$self->hex_to_ascii($info),"
($meta_length)\n");
my $extra = MalwarePatternType->decode($info);
# update the type
my $hash = $local_hashes[$count];
$hash->{type} = $extra->{pattern_type};
$local_hashes[$count] = $hash;
$count++;
}
}