From patchwork Sat Aug 17 16:23:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11099169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21C871399 for ; Sat, 17 Aug 2019 16:24:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FFC420881 for ; Sat, 17 Aug 2019 16:24:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02663289A0; Sat, 17 Aug 2019 16:24:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D3AF20881 for ; Sat, 17 Aug 2019 16:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726012AbfHQQYA (ORCPT ); Sat, 17 Aug 2019 12:24:00 -0400 Received: from mout.web.de ([212.227.15.3]:44347 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfHQQYA (ORCPT ); Sat, 17 Aug 2019 12:24:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1566059033; bh=waSB8/aHqHMsVjuJRT8m8AWj4bRHv7rgrqOmJvDZ6d8=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=ly40i7gHtE6UOmomzr2kw1WP3zY2SSEwL6BcvrBUlRaUT1eXGasWTLCmy9L0ffRU3 jAXK6KcqY+WhwDeBLfzBfh7YcoRt8C+lhC/gyxeaVUklO4kTiZ6K63K790fW0rh1xb 5BN+UUlSfjpg00b5jpLpSOO2+sdwv1eexR9h/2jk= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.23] ([79.203.24.71]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LyOuM-1iMrbr2xjq-015oZu; Sat, 17 Aug 2019 18:23:53 +0200 Subject: [PATCH 1/4] archive-tar: report wrong pax extended header length From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git Mailing List Cc: Junio C Hamano References: Message-ID: Date: Sat, 17 Aug 2019 18:23:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:4kX3AVhKbDdZQcqI4KUNFl7L2XtMODV45joMupGeOfN73zocpw4 Al4IZbm0ZqYqrUyWsFtb8vGEVmP13lTMT+jnLWyBwOM4lrPdE4tNrWkg27FvHec/JnTB4vv xbPIFZf+VfspPYscBewuTuYcd2KHN3CBGRNPbL/eASoRwNJp70rf5R0TOwtuE9IsCagf7Yk +9eBLPMwmeEEM0ZRkhLYQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:ti4zYi/3jP4=:rbgGCvAhh19WxF9+kNp/ZH 0FGV9/mxOsFPoV/u8t8lpOmeqJ7IB26ew/HGIierqtQ+ADjL8foLG5IHWBoLGMTmebwswfY+E 1ipO7KUd1ACWn2rSE0Z2VCDvVhAwqFw6RVAUQKxpI8jvviet54snKc884+fi92NMHtSuC+byt CHoQjYcMfyOKss7XohDm1tA1/r3vs2bGMc9zNvONaav7jtMLWvxewRBGW9TXJ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org X-Virus-Scanned: ClamAV using ClamSMTP Extended header entries contain a length value that is a bit tricky to calculate because it includes its own length (number of decimal digits) as well. We get it wrong in corner cases. Add a check, report wrong results as a warning and add a test for exercising it. Signed-off-by: René Scharfe --- archive-tar.c | 6 ++++++ t/t5004-archive-corner-cases.sh | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) -- 2.23.0 diff --git a/archive-tar.c b/archive-tar.c index 3e53aac1e6..355c8142c6 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -144,6 +144,7 @@ static int stream_blocked(const struct object_id *oid) static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, const char *value, unsigned int valuelen) { + size_t orig_len = sb->len; int len, tmp; /* "%u %s=%s\n" */ @@ -155,6 +156,11 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, strbuf_addf(sb, "%u %s=", len, keyword); strbuf_add(sb, value, valuelen); strbuf_addch(sb, '\n'); + + if (len != sb->len - orig_len) + warning("pax extended header length miscalculated as %d" + ", should be %"PRIuMAX, + len, (uintmax_t)(sb->len - orig_len)); } /* diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 271eb5a1fd..2f15d1899d 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -204,4 +204,24 @@ test_expect_success EXPENSIVE,LONG_IS_64BIT,UNZIP,UNZIP_ZIP64_SUPPORT,ZIPINFO \ grep $size big.lst ' +build_tree() { + perl -e ' + my $hash = $ARGV[0]; + foreach my $order (2..6) { + $first = 10 ** $order; + foreach my $i (-13..-9) { + my $name = "a" x ($first + $i); + print "100644 blob $hash\t$name\n" + } + } + ' "$1" +} + +test_expect_failure 'tar archive with long paths' ' + blob=$(echo foo | git hash-object -w --stdin) && + tree=$(build_tree $blob | git mktree) && + git archive -o long_paths.tar $tree 2>stderr && + test_must_be_empty stderr +' + test_done From patchwork Sat Aug 17 16:24:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11099171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8A9C1399 for ; Sat, 17 Aug 2019 16:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C840C20881 for ; Sat, 17 Aug 2019 16:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B93AF289A0; Sat, 17 Aug 2019 16:24:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6277D20881 for ; Sat, 17 Aug 2019 16:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726217AbfHQQYG (ORCPT ); Sat, 17 Aug 2019 12:24:06 -0400 Received: from mout.web.de ([212.227.15.14]:53403 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfHQQYG (ORCPT ); Sat, 17 Aug 2019 12:24:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1566059041; bh=paqw9ABYIxXOwh+DkcFguvyQFjXNjPUjLVRxMhZZaPI=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=fEq9u14R6olSvMkr9MG47f6q4YUlk1sifaKeu75YYGUB5u5MQJPsNgrKuTZxCTe0l dDL2zT7UDRb+EYTkklfqrdmEG/Ei89tCE+fQuRnosGm9i8xe6GHoYoDaCmja8BLCj/ pfukGo8XC+A9HhK9vZ0hkhG0wa8hHsanyqB+Plg4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.23] ([79.203.24.71]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lmchn-1iZBOU3Gt9-00aE4V; Sat, 17 Aug 2019 18:24:01 +0200 Subject: [PATCH 2/4] archive-tar: fix pax extended header length calculation From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git Mailing List Cc: Junio C Hamano References: Message-ID: <4b04cf3f-966a-3aa9-6a30-7ac3a234e1ed@web.de> Date: Sat, 17 Aug 2019 18:24:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:MLvEs83HScZGu58cHBO8L8IvwMlZdBsbBLskf7YZMUUUjfNi5d9 KhML3a8ZOUOfFbSoidOwfazcx/xqca7Ko9xL5MFyajCz85JgYXrsdxL2VXgQNsqveqWUINx IXCZz2iSYgsiHEj5TFpS91y1cyfUXSLFRCsuQNJkWfddcS0EjVST2InXimo5KShBpeMQEM0 VYUeEhXI3reTXH2cj28qA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Oe5J+b5MT0Y=:McZT0Eb6P91SLPCdMEZZUA aSfS6ulpA3/GQJKUf2zDFmPofK2Ii7QGIq2BWLHJ34MULS6Nxh9yezGqYFiV84CVs4CctUktV Qzzj44v0ZAgROSwVkNh2GAK5Ej1Jqr5HcvpjeyINWSWMPxg/iZwb7Yu0rvNDwFfHSijCD+nH1 udmMV1lvwr7RU81N/YScWNyv7HmKRxgyGSyrtYkL3oxGtY9bpEYET4V47q06SWUEKRXnRNAxR wHDaNcprrTbii9Xwbx9JNAOOL4pCpZ4SIS5M5LnWotiRHrHUDsAS+PDamsbsbGidP6C/fEe03 4G+Hh5FkSZEXgG3LwauzaXSAEj+5PUdYZbYW61C5F7lto8EkYdx5FnTG5feiqNOxuBYEXMDAe sVnwUtDKF44SHVqLDxd0F8Yh0qFMthOYUoswrRb0QduQHO64ejLGFxQPi56qhyzktl5WJj+vO r0/MYocHvK7jKWrorvEFQlshPMPxUupG85rfpNwLcYkoZk+QI5nlIlVUnRCNdcWmEGiqWvU9u awqOeBY5xZfV5a1Z8+/d43Smp0396M/jTQFSEjKPcl4ClVcv7NcodpROaBJWHoq1dzQAfp0rW KqV3q7jHu3AwsVxpPi0N7pHBQoy713ZzhAltq1n54thcjQA3qkRkWkYXjCNbPRB3ySertg2Vq g+2vMWUjB2ZmHirzawV/rJr4fXtAaoBskBRFkdq1QBBOCcwuPNJ9nhbN4LgMtPV0vufu9HnwC WLT3PwIZ7jFRDCiPLzCoBx2mDvK4t4QYVkPKO9wpc1GXrbslMruiteW3rfo2DDL2KwKy2WaFw /2nMMzn2JUwuXcWlvzDApbiJ1BZu2cjXEZpGC9xS2qYJG8q4rEqfshBeopEYhBcYI/wM6HoPT Zf4qzgX9Yt54ImpAM6FqIryVVPohwvKXMZGQOPJl7745MTdAISACVn3vDHtFcUyUXH5myi02v sdJ7O2GiTH+5MbdaM1SaojlmbMukUPeRCITVuF8mwxTf4zZQPVVwYnYaD6gwpdlClqms+++05 rqpFK1NeKHCjmqtzF9nZ3BuiJpaOo9uPEHV2yhrVzhqpbRnvmxMh0Zu7haLuDhZ0Sq1t/ItGd /a6ku19rXFMsTbhgF1Dt2pFntZAhmDkj1+k/Z8tJBh6TrZZNMba+0SW7p3fxC/xbSmLZ0Jnu8 ogBEo= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A pax extended header records starts with a decimal number. Its value is the length of the whole record, including its own length. The calculation of that number if strbuf_append_ext_header() is off by one in case the length of the rest is close to a higher order of magnitude. This affects paths and link targets a bit shorter than 1000, 10000, 100000 etc. characters -- paths with a length of up to 100 fit into the tar header and don't need a pax extended header. The mistake has been present since the function was added by ae64bbc18c ("tar-tree: Introduce write_entry()", 2006-03-25). Account for digits added to len during the loop and keep incrementing until we have enough space for len and the rest. The crucial change is to check against the current value of len before each iteration, instead of against its value before the loop. Signed-off-by: René Scharfe --- archive-tar.c | 2 +- t/t5004-archive-corner-cases.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.23.0 diff --git a/archive-tar.c b/archive-tar.c index 355c8142c6..4395a29ffb 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -149,7 +149,7 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, /* "%u %s=%s\n" */ len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1; - for (tmp = len; tmp > 9; tmp /= 10) + for (tmp = 1; len / 10 >= tmp; tmp *= 10) len++; strbuf_grow(sb, len); diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 2f15d1899d..4966a74b4d 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -217,7 +217,7 @@ build_tree() { ' "$1" } -test_expect_failure 'tar archive with long paths' ' +test_expect_success 'tar archive with long paths' ' blob=$(echo foo | git hash-object -w --stdin) && tree=$(build_tree $blob | git mktree) && git archive -o long_paths.tar $tree 2>stderr && From patchwork Sat Aug 17 16:24:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11099173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A8C21399 for ; Sat, 17 Aug 2019 16:24:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AE9720881 for ; Sat, 17 Aug 2019 16:24:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EF58289A0; Sat, 17 Aug 2019 16:24:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AD802899D for ; Sat, 17 Aug 2019 16:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726220AbfHQQYQ (ORCPT ); Sat, 17 Aug 2019 12:24:16 -0400 Received: from mout.web.de ([212.227.15.14]:53257 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfHQQYQ (ORCPT ); Sat, 17 Aug 2019 12:24:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1566059053; bh=6EA/LZJS6omXR7+upmppamUGTLDaHLjbc/vwR3z2mic=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=rBnfhO5hBWk4FAqms8A1DtAhrYh0MczowkuOdLYyWOhWA756Vw1wLtYtdw4iJd6/d 0fdr5NgcWl4QDnNJTKKC4/CfF4c9qFH/1Q/Unh897ZTeNkBjKOfuIXb1JKwIwn1WWI 4Scix1dBaQu0hK2fjkUSPdsW5DpIe1zPf82CFNPc= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.23] ([79.203.24.71]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lb289-1ifBvo2Vsf-00kdAy; Sat, 17 Aug 2019 18:24:13 +0200 Subject: [PATCH 3/4] archive-tar: use size_t in strbuf_append_ext_header() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git Mailing List Cc: Junio C Hamano References: Message-ID: <1933ad5e-612f-b5ce-065b-f435338c3c9c@web.de> Date: Sat, 17 Aug 2019 18:24:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:Il3LCK8RX4jNjDrcKWOqOjzDVeSiSgV5jkbIm+ajX6wRnCncMeN oxuW3BjqeS4nQM/Tvy/ZlaP3qR55/+mwlqquPI7ttd62VzH7txImihWw4yLkfPZYhT1EUJL qcOTTHUUiWWfwD7p7pMaH5Z5gCVszjgSW8sxSUYnUAEKw8Cs1zdcC5o1IjQukgISJK4X7z0 BciaaKfmZRlMTBOGQjlDA== X-UI-Out-Filterresults: notjunk:1;V03:K0:qD4jKnagt4o=:FAK19FPM6PF1lVJ9eD7a8S 0Qcrt7uCWlKt1CfpaMLf+Do09z55f1T7vBmYbrY138rma4gU3ieEH3ARBVe2dRe/78eT3dL0d F0o+meRVbAc/3ghOFNg3JpreZl8YEwV+BMM3fMr4uB7oY3H1on5kK0/BgUNd8OKuC+HxvyeKi UWVirA58gWFfHLc8AkfN8cyF0EiJY2H5sxkBG3RugLSP4R5W3rCcDB66R4bwpkYm5QK57YLyG 1ReewSLLdkFP6Q9HQ/1s2kLsWyVdZT0S3yWb6J4Ox3176igv77ugzFIdqNnKGh5FnPwgn55gT c8Le/H18F/bYgHSFhDVslf0DWUPNT7t3rnpwfk0gZ8oP7U1DxuOwhXI/ZP298J5ZtBsuczwFH kiR151EGmLi0ebztGZc+vYVgfIaZDogv3QtcNQRsSqJiUXmjt1qGumZDyycmes9hkOHzf0RBN h2CieZv1LuPRzVjSwgyf0Sy+7s25ln5LqJ4os/LdNAAcvZARB73InrB4eg8bPsUR25II6yBKr Pa3IDW6o1gV3cpFeCcFi5tovPwwd9ixFxXjF+bVyn+MYWTk2YFvMPfX7qL43uEPpMLkMNaTlw KMn4kVLeDkXReSkGnteH8kBhn9DATyZ/Y8qFZ76mEL8bUn2Z0CnaOZB3WHbxYJf12MBWgU/dS El90nK5JXAj3IK/zBUcJKc+lTNrsurBZe+rkg50zSRw3FnUttOIvMzVotXSeo+2i4dAt0OxHD FdAIgXypH7LYGy5yHAT7/Rr46lxbUt1kCS7Wg+DwWDgccnedOmM4CtLCFpfNKyGB/Teh3fWa1 nmTp+bevKodb0jKUmYQfSH/9Blz8Fd5+tKtT+GKo1Bz4YYGADlNJdS5f3CcFETAEww4Us5FK0 +2DUeGOmyLcT02VbhftzY7D8009hN1oPoE7KMg/e3bphliSVcwnoH6H2rfvpFSEm/EJ2Og8Xu uPs5l+oopQ0tk16lV0OYD/X0j786cKTZBdQrtFXQS7qL3Y89wSMOzDCla7DTq7mdIfWgA5ALa KQ7apLiZEufC6WpGoYEB8fnZgBIZZdyKPXd+q1SSTv2P6ny5B7G2q1CFoacYAwVRsOwGWcoh4 tvtpaQktBv+6v4SnVVUeGAwAaqD4fvagOcPHiD6+YP8cSneJglSsPRlo0gUxI88Q7OJW3FeXb bM3ao= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP One of its callers already passes in a size_t value. Use it consistently in this function. Signed-off-by: René Scharfe --- archive-tar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.23.0 diff --git a/archive-tar.c b/archive-tar.c index 4395a29ffb..9d09edd547 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -142,10 +142,10 @@ static int stream_blocked(const struct object_id *oid) * string and appends it to a struct strbuf. */ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, - const char *value, unsigned int valuelen) + const char *value, size_t valuelen) { size_t orig_len = sb->len; - int len, tmp; + size_t len, tmp; /* "%u %s=%s\n" */ len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1; @@ -153,14 +153,14 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, len++; strbuf_grow(sb, len); - strbuf_addf(sb, "%u %s=", len, keyword); + strbuf_addf(sb, "%"PRIuMAX" %s=", (uintmax_t)len, keyword); strbuf_add(sb, value, valuelen); strbuf_addch(sb, '\n'); if (len != sb->len - orig_len) - warning("pax extended header length miscalculated as %d" + warning("pax extended header length miscalculated as %"PRIuMAX ", should be %"PRIuMAX, - len, (uintmax_t)(sb->len - orig_len)); + (uintmax_t)len, (uintmax_t)(sb->len - orig_len)); } /* From patchwork Sat Aug 17 16:24:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11099175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A674856FE for ; Sat, 17 Aug 2019 16:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 972C12899D for ; Sat, 17 Aug 2019 16:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ABF6289A1; Sat, 17 Aug 2019 16:24:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DF222899D for ; Sat, 17 Aug 2019 16:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726120AbfHQQY1 (ORCPT ); Sat, 17 Aug 2019 12:24:27 -0400 Received: from mout.web.de ([212.227.15.3]:34907 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfHQQY1 (ORCPT ); Sat, 17 Aug 2019 12:24:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1566059063; bh=DBvufhzjQItO41/xuB1YvDY/dZ+FA08yyk9LRsiF5xE=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=n46L8AgMH78BLuNvKaFsliVwiMYDoTinVdUn2MS4BBstQO3j3sFd0+Itoi/FPW4j1 WuAiU+g9xHv7ZS0O8ihf1hqwZ1obpx7I/TveOQ/4Aq0grSHHZ/gWv22H+LsmdRaBzt fm4mOuj2KGvPXFpOsEdmlcIQq8iltWNITUaoG7lg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.23] ([79.203.24.71]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M6UmJ-1iB3u82rff-00ySDi; Sat, 17 Aug 2019 18:24:23 +0200 Subject: [PATCH 4/4] archive-tar: turn length miscalculation warning into BUG From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git Mailing List Cc: Junio C Hamano References: Message-ID: Date: Sat, 17 Aug 2019 18:24:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:/qtC+MfUG9Dyk2ZHkc/5vAcUaNjAlUMj/YimXBx1V7rpWvL7W32 BUwSM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t/erKeNOIyIMLF//l PANedIFbm6oNesdEnibcksO6K/RJ5hzo3MR+s27qYk7t0g24faRKIPk0ZUiheq/UlzszpndTo CX6xv1ALcbdMIIXkaq/+WbWnfVTCqm7G7+Ypvo+05wSi74J3YJmR+fsGEfCdyQ0fJOC3xvZBg hXtdF0GvOIUWTFAlSDozc58zl/3mOpGr1I3Npsbs79ZlEp2lz2XnAsuAcQhKViyqWurxKdeVi ZrmlNe5PULt52zajomPRmrwAQGaiaLcnpQVyWHXNxdFKzDbWMq43goB5aczLDMTrTQCDqLhp2 k8VlR4I7uZPvcMWMO1wiiPBpbB6GQEKRmhe2czOhlpBZ6Gkg== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we're confident our pax extended header calculation is correct, turn the criticality of the assertion up to the maximum, from warning right up to BUG. Simplify the test, as the stderr comparison step would not be reached in case the BUG message is triggered. Signed-off-by: René Scharfe --- archive-tar.c | 6 +++--- t/t5004-archive-corner-cases.sh | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) -- 2.23.0 diff --git a/archive-tar.c b/archive-tar.c index 9d09edd547..e16d3f756d 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -158,9 +158,9 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, strbuf_addch(sb, '\n'); if (len != sb->len - orig_len) - warning("pax extended header length miscalculated as %"PRIuMAX - ", should be %"PRIuMAX, - (uintmax_t)len, (uintmax_t)(sb->len - orig_len)); + BUG("pax extended header length miscalculated as %"PRIuMAX + ", should be %"PRIuMAX, + (uintmax_t)len, (uintmax_t)(sb->len - orig_len)); } /* diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 4966a74b4d..3e7b23cb32 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -220,8 +220,7 @@ build_tree() { test_expect_success 'tar archive with long paths' ' blob=$(echo foo | git hash-object -w --stdin) && tree=$(build_tree $blob | git mktree) && - git archive -o long_paths.tar $tree 2>stderr && - test_must_be_empty stderr + git archive -o long_paths.tar $tree ' test_done