From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D16DE1F518 for ; Tue, 17 Oct 2023 23:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1697585896; bh=1nuMSR6TXwbD+UktDpy2fzzeCi/f1wbhmSb3AnMcLj4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dqMqIuxwoSQGa+7WUWk2u27e5IGYDX7IF6d/c7RHc4+qPjRN8CrDGfqgFNx1CVdJh Q9IQXk50sYXzoSP3bOaRknD5ozET4JlbQseSdG3IA03ILynKvQsTDcfAVsvzlW69pl RROsdG8e0DXl8WQj29nrsoSY2FiBKPB8Y3UDK0zc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/30] import: use read_all to detect short reads Date: Tue, 17 Oct 2023 23:37:50 +0000 Message-ID: <20231017233815.1637932-6-e@80x24.org> In-Reply-To: <20231017233815.1637932-1-e@80x24.org> References: <20231017233815.1637932-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Our Import package was depending on Git, anyways. --- lib/PublicInbox/Import.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 6bb2c66d..fb70b91b 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -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;