]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
import: use read_all to detect short reads
authorEric Wong <e@80x24.org>
Tue, 17 Oct 2023 23:37:50 +0000 (23:37 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Oct 2023 20:50:23 +0000 (20:50 +0000)
Our Import package was depending on Git, anyways.

lib/PublicInbox/Import.pm

index 6bb2c66d868407a4d7edb4d48eabe779dfc61dc4..fb70b91b6b9b27e6e6f88b97ad39180d354731bb 100644 (file)
@@ -21,6 +21,7 @@ use POSIX qw(strftime);
 use autodie qw(read close socketpair);
 use Carp qw(croak);
 use Socket qw(AF_UNIX SOCK_STREAM);
+use PublicInbox::Git qw(read_all);
 
 sub default_branch () {
        state $default_branch = do {
@@ -114,8 +115,7 @@ sub _cat_blob ($$) {
        local $/ = "\n";
        my $info = <$io> // die "EOF from fast-import / cat-blob: $!";
        $info =~ /\A[a-f0-9]{40,} blob ([0-9]+)\n\z/ or return;
-       my $n = read($io, my $buf, my $len = $1 + 1);
-       $n == $len or croak "cat-blob: short read: $n < $len";
+       my $buf = read_all($io, my $len = $1 + 1);
        my $lf = chop $buf;
        croak "bad read on final byte: <$lf>" if $lf ne "\n";
        \$buf;
@@ -562,9 +562,7 @@ sub replace_oids {
                } elsif (/^data ([0-9]+)/) {
                        # only commit message, so $len is small:
                        push @buf, $_;
-                       my $n = read($rd, my $buf, my $len = $1);
-                       $len == $n or croak "short read ($n < $len)";
-                       push @buf, $buf;
+                       push @buf, read_all($rd, my $len = $1);
                } elsif (/^M 100644 ([a-f0-9]+) (\w+)/) {
                        my ($oid, $path) = ($1, $2);
                        $tree->{$path} = 1;