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 &&