From patchwork Mon Apr 25 15:14:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 53191 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A23A385842B for ; Mon, 25 Apr 2022 15:16:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A23A385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1650899813; bh=QMvpUr7aHiovkCeH1MYOg13BVEyC5Ta8Ti0IBlBFUOA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Oyvdge5ReXSgJt0A/v1csxgx9+apm7M/pXSKXeQhJ7AvQ0thryczbxVUrD3LRG08m 0i/rmHXfqj0v9aOaOZpAIA5zAmOWPhIQEDf3KNZ77WYdiH1xYN0VYFqyXVt1f/E1mS TGG8FILUClqeKkK2tNwO2B4vwQiQO4p5Ioak1zdQ= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E3D233858025 for ; Mon, 25 Apr 2022 15:15:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E3D233858025 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-MP-gyo5rPH2hZROYSnQRmw-1; Mon, 25 Apr 2022 11:15:29 -0400 X-MC-Unique: MP-gyo5rPH2hZROYSnQRmw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E95A3801E80 for ; Mon, 25 Apr 2022 15:15:28 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id D99E3C15D5C; Mon, 25 Apr 2022 15:15:01 +0000 (UTC) To: fche@redhat.com Subject: [PATCH] debuginfod: ensure X-DEBUGINFOD-SIZE contains file size Date: Mon, 25 Apr 2022 11:14:37 -0400 Message-Id: <20220425151437.56310-1-amerey@redhat.com> In-Reply-To: <20220422232731.GF23969@redhat.com> References: <20220422232731.GF23969@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aaron Merey via Elfutils-devel From: Aaron Merey Reply-To: Aaron Merey Cc: elfutils-devel@sourceware.org Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" Hi Frank, On Fri, Apr 22, 2022 at 7:27 PM Frank Ch. Eigler wrote: > > - add_mhd_response_header (r, "X-DEBUGINFOD-SIZE", > > - to_string(fs.st_size).c_str()); > > > + rc = fstat (fd, &fs); > > + if (rc == 0) > > + add_mhd_response_header (r, "X-DEBUGINFOD-SIZE", > > + to_string(fs.st_size).c_str()); > > + else > > + { > > + close (fd); > > + throw libc_exception (errno, string("stat ") + b_source1 + " archive " + b_source0); > > + } > > It shouldn't require a new fstat -- the archive component file's size > should be available from libarchive already: archive_entry_size(e); Fixed. Aaron From 08e448456e27339aeb326828d44069028518038a Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Mon, 25 Apr 2022 11:10:46 -0400 For archived files X-DEBUGINFOD-SIZE currently contains the size of the archive instead of the size of the uncompressed file. Fix this. Also add testcases to verify X-DEBUGINFOD-SIZE contains uncompressed file sizes. Signed-off-by: Aaron Merey --- debuginfod/debuginfod.cxx | 2 +- tests/run-debuginfod-response-headers.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index adca8208..4aaf41c0 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1790,7 +1790,7 @@ handle_buildid_r_match (bool internal_req_p, add_mhd_response_header (r, "Content-Type", "application/octet-stream"); add_mhd_response_header (r, "X-DEBUGINFOD-SIZE", - to_string(fs.st_size).c_str()); + to_string(archive_entry_size(e)).c_str()); add_mhd_response_header (r, "X-DEBUGINFOD-ARCHIVE", b_source0.c_str()); add_mhd_response_header (r, "X-DEBUGINFOD-FILE", file.c_str()); diff --git a/tests/run-debuginfod-response-headers.sh b/tests/run-debuginfod-response-headers.sh index 10b2ab49..62c43887 100755 --- a/tests/run-debuginfod-response-headers.sh +++ b/tests/run-debuginfod-response-headers.sh @@ -86,6 +86,14 @@ grep 'X-DEBUGINFOD-FILE: ' vlog-find$PORT1.2 grep 'X-DEBUGINFOD-SIZE: ' vlog-find$PORT1.2 grep 'X-DEBUGINFOD-ARCHIVE: ' vlog-find$PORT1.2 +# Check that X-DEBUGINFOD-SIZE matches the size of each file +for file in vlog-find$PORT1.1 vlog-find$PORT1.2 +do + st_size=$(stat -c%s $(tail -n 1 $file)) + x_debuginfod_size=$(grep 'X-DEBUGINFOD-SIZE' $file | egrep -o '[0-9]+') + test $st_size -eq $x_debuginfod_size +done + kill $PID1 wait $PID1 PID1=0