]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: prevent empty {bytes} field in saved search
authorEric Wong <e@80x24.org>
Fri, 8 Mar 2024 21:05:03 +0000 (21:05 +0000)
committerEric Wong <e@80x24.org>
Sun, 10 Mar 2024 21:35:59 +0000 (21:35 +0000)
Noticed while tracking down fast-import crash bug report.

Link: https://public-inbox.org/meta/CAL_JsqK7P4gjLPyvzxNEcYmxT4j6Ah5f3Pz1RqDHxmysTg3aEg@mail.gmail.com/
lib/PublicInbox/LeiSearch.pm
lib/PublicInbox/LeiToMail.pm
lib/PublicInbox/OverIdx.pm

index 29e3213f3688b954afdea4d9539317c365746f6f..684668c50f0f6c3390c269fd63a42bdbed262cc1 100644 (file)
@@ -103,6 +103,8 @@ sub xoids_for {
                for my $o (@overs) {
                        my ($id, $prev);
                        while (my $cur = $o->next_by_mid($mid, \$id, \$prev)) {
+                               # {bytes} may be '' from old bug
+                               $cur->{bytes} = 1 if $cur->{bytes} eq '';
                                next if $cur->{bytes} == 0 ||
                                        $xoids->{$cur->{blob}};
                                $git->cat_async($cur->{blob}, \&_cmp_1st,
index a816df6c54e183db332eb8ce20966af024b885ec..dfae29e95f1a5fc811c252033434c7c1e2146849 100644 (file)
@@ -149,6 +149,7 @@ sub git_to_mail { # git->cat_async callback
                                                "W: $oid is $type (!= blob)");
                $size or return $self->{lei}->child_error(0,"E: $oid is empty");
                $smsg->{blob} eq $oid or die "BUG: expected=$smsg->{blob}";
+               $smsg->{bytes} ||= $size;
                $self->{wcb}->($bref, $smsg);
        };
        $self->{lei}->fail("$@ (oid=$oid)") if $@;
index c9c25828a1c4b0155fdffad5ecb9eb456e9260ce..4f8533f7284b6284ead1422f100cba61b0329b2c 100644 (file)
@@ -17,6 +17,7 @@ use PublicInbox::MID qw/id_compress mids_for_index references/;
 use PublicInbox::Smsg qw(subject_normalized);
 use Compress::Zlib qw(compress);
 use Carp qw(croak);
+use bytes (); # length
 
 sub dbh_new {
        my ($self) = @_;
@@ -263,7 +264,10 @@ sub ddd_for ($) {
 
 sub add_overview {
        my ($self, $eml, $smsg) = @_;
-       $smsg->{lines} = $eml->body_raw =~ tr!\n!\n!;
+       my $raw = $eml->body_raw;
+       $smsg->{lines} = $raw =~ tr!\n!\n!;
+       $smsg->{bytes} //= bytes::length $raw;
+       undef $raw;
        my $mids = mids_for_index($eml);
        my $refs = $smsg->parse_references($eml, $mids);
        $mids->[0] //= do {