Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Mail/SpamAssassin/Handler/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ sub _basename {
sub _zip_entry_count {
my ($dataref) = @_;
my $len = defined $$dataref ? length $$dataref : 0;
return undef if $len < 22;
return if $len < 22;

# Search backwards for the EOCD signature within the comment window. Scanning
# a bounded tail (not the whole file) keeps this cheap on large archives.
my $window = $len < 22 + 0xFFFF ? $len : 22 + 0xFFFF;
my $tail = substr($$dataref, $len - $window);
my $pos = rindex($tail, "PK\x05\x06");
return undef if $pos < 0;
return undef if $pos + 12 > length $tail; # not enough bytes for the count field
return if $pos < 0;
return if $pos + 12 > length $tail; # not enough bytes for the count field

my $count = unpack('v', substr($tail, $pos + 10, 2));

Expand Down Expand Up @@ -464,7 +464,7 @@ sub _run_unrar {
chomp(my $e = $err);
log_warn("unrar error: $e");
}
return undef;
return;
}

return $resp;
Expand Down
8 changes: 4 additions & 4 deletions lib/Mail/SpamAssassin/Handler/Image.pm
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ sub _resolve_binary {
warn "image: $warn_msg\n" if defined $warn_msg;
dbg("image: $label not found, related conversions disabled")
if !defined $warn_msg;
return undef;
return;
}

# Identify an image's real type and pixel dimensions from its leading bytes.
Expand Down Expand Up @@ -617,7 +617,7 @@ sub _ocr {
chomp(my $e = $err);
info("image: tesseract error: %s", $e);
}
return undef;
return;
}

return $resp;
Expand All @@ -634,7 +634,7 @@ sub _heif_to_png {
my $convert = $self->_heif_convert($conf);
if (!$convert) {
dbg("image: cannot OCR HEIF, heif-convert not available");
return undef;
return;
}
my $secs = $conf->{handler_time_limit} || 10;

Expand Down Expand Up @@ -718,7 +718,7 @@ sub _heif_to_png {
chomp(my $e = $err);
info("image: heif-convert error: %s", $e);
}
return undef;
return;
}

# Return a ref to the converted bytes (handle_image threads it on by ref).
Expand Down
30 changes: 15 additions & 15 deletions lib/Mail/SpamAssassin/Handler/PDF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ sub _resolve_binary {
return $path;
}
log_dbg("$label not found, text extraction disabled (set pdf_pdftotext_path)");
return undef;
return;
}

# _extract_text($pms, $dataref): run pdftotext on the decoded PDF bytes and
Expand All @@ -452,7 +452,7 @@ sub _extract_text {

my $conf = $pms->{conf} || $self->{main}->{conf};
my $bin = $self->_pdftotext($conf);
return undef unless defined $bin;
return unless defined $bin;

my $pages = $conf->{pdf_text_max_pages};
$pages = DEFAULT_TEXT_MAX_PAGES unless defined $pages;
Expand Down Expand Up @@ -525,7 +525,7 @@ sub _extract_text {
chomp(my $e = $err);
log_warn("pdftotext error: $e");
}
return undef;
return;
}

return $resp;
Expand All @@ -545,20 +545,20 @@ sub _extract_text {
sub _encode_image {
my ($self, $img) = @_;
my $bytes = $img->{bytes};
return undef unless defined $bytes && length $bytes;
return unless defined $bytes && length $bytes;

my $format = $img->{format} // '';
return { type => 'image/jpeg', data => $bytes } if $format eq 'jpeg';
return { type => 'image/tiff', data => $bytes } if $format eq 'tiff';
return undef unless $format eq 'raw';
return unless $format eq 'raw';

my $w = $img->{width};
my $h = $img->{height};
my $bpc = $img->{bpc};
my $cs = $img->{colorspace};

return undef unless defined($w) && defined($h) && $w > 0 && $h > 0;
return undef if ref($cs); # Indexed/ICCBased/etc. arrays - skip
return unless defined($w) && defined($h) && $w > 0 && $h > 0;
return if ref($cs); # Indexed/ICCBased/etc. arrays - skip
$cs = '' unless defined($cs);

my ($channels, $samples);
Expand All @@ -567,7 +567,7 @@ sub _encode_image {
# Bilevel: expand 1 bit/pixel (row byte-aligned) to 8-bit gray. PDF sample
# 0 = black, so bit 0 -> 0x00, bit 1 -> 0xff.
my $row_bytes = int(($w + 7) / 8);
return undef if length($bytes) < $row_bytes * $h;
return if length($bytes) < $row_bytes * $h;
my $gray = '';
for my $y (0 .. $h-1) {
my $row = substr($bytes, $y * $row_bytes, $row_bytes);
Expand All @@ -577,22 +577,22 @@ sub _encode_image {
($channels, $samples) = (1, $gray);
}
elsif ( $cs =~ /rgb/i ) {
return undef unless !defined($bpc) || $bpc == 8;
return undef if length($bytes) < $w * $h * 3;
return unless !defined($bpc) || $bpc == 8;
return if length($bytes) < $w * $h * 3;
($channels, $samples) = (3, substr($bytes, 0, $w * $h * 3));
}
elsif ( $cs =~ /gray/i || $cs eq '' ) {
return undef unless !defined($bpc) || $bpc == 8;
return undef if length($bytes) < $w * $h;
return unless !defined($bpc) || $bpc == 8;
return if length($bytes) < $w * $h;
($channels, $samples) = (1, substr($bytes, 0, $w * $h));
}
else {
# CMYK / Separation / unknown - skip
return undef;
return;
}

my $png = _raw_to_png($w, $h, $channels, $samples);
return undef unless defined $png;
return unless defined $png;
return { type => 'image/png', data => $png };
}

Expand All @@ -609,7 +609,7 @@ sub _raw_to_png {
$raw .= "\x00" . substr($samples, $_ * $row_bytes, $row_bytes) for 0 .. $h-1;

my $idat = compress($raw);
return undef unless defined $idat;
return unless defined $idat;

my $png = "\x89PNG\x0d\x0a\x1a\x0a";
$png .= _png_chunk('IHDR', pack('NNCCCCC', $w, $h, 8, $color_type, 0, 0, 0));
Expand Down
6 changes: 3 additions & 3 deletions lib/Mail/SpamAssassin/PDF/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ sub _get_obj {
my $core = $self->{core};

# return undef for non-existent objects
return undef unless defined($ref) && defined($self->{xref}->{$ref});
return unless defined($ref) && defined($self->{xref}->{$ref});

if ( !defined($self->{object_cache}->{$ref}) ) {
my ($objnum,$gennum) = $ref =~ /^(\d+) (\d+) R$/;
Expand Down Expand Up @@ -883,7 +883,7 @@ sub _ccitt_to_tiff {

my $w = $parms->{Columns};
my $h = $parms->{Rows};
return undef unless defined($w) && defined($h) && $w > 0 && $h > 0;
return unless defined($w) && defined($h) && $w > 0 && $h > 0;

my $k = $parms->{K} || 0;
my ($compression, $t4options);
Expand All @@ -895,7 +895,7 @@ sub _ccitt_to_tiff {
# (T4Options bit 2). A Group 4 stream that sets it can't be described in TIFF,
# so decline rather than hand over data that would decode to garbage.
if ( $parms->{EncodedByteAlign} ) {
return undef if $compression == 4;
return if $compression == 4;
$t4options |= 0x4;
}

Expand Down