From patchwork Fri Apr 22 22:26:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 53138 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 ADE3E3856DC6 for ; Fri, 22 Apr 2022 22:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADE3E3856DC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1650666415; bh=oWyxNV5z/FxmC3UlhiGsRjkKCTu3PQ0siFXwP+PJfHc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=DuGQKOXVk0Y+/t5m3Hx+f1KYTwuUlqUn4cmimcWXu4gtPjzBUD38QfV3BMqS5rFfh 0NWpuaj/o33MeCikNMW6HunypxdDpNVjM4b5wWyfCzp7D0pwFJCfjWF01wWpXhEwsD m/GOpNEqh8wSPwl99NKzeOx0CV74Sg3gGV3pIuB4= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id D16643858C83 for ; Fri, 22 Apr 2022 22:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D16643858C83 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-VQjPwZ1_OuanpWe_nIG6SQ-1; Fri, 22 Apr 2022 18:26:45 -0400 X-MC-Unique: VQjPwZ1_OuanpWe_nIG6SQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3604F1E17FE7 for ; Fri, 22 Apr 2022 22:26:45 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id F09F1111E410; Fri, 22 Apr 2022 22:26:44 +0000 (UTC) To: elfutils-devel@sourceware.org Subject: [PATCH 2/2] debuginfod: ensure X-DEBUGINFOD-SIZE contains file size Date: Fri, 22 Apr 2022 18:26:41 -0400 Message-Id: <20220422222641.316502-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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 Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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 | 11 +++++++++-- tests/run-debuginfod-response-headers.sh | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 9c0217f6..d61757ae 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1789,11 +1789,18 @@ handle_buildid_r_match (bool internal_req_p, std::string file = b_source1.substr(b_source1.find_last_of("/")+1, b_source1.length()); 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()); add_mhd_response_header (r, "X-DEBUGINFOD-ARCHIVE", b_source0.c_str()); add_mhd_response_header (r, "X-DEBUGINFOD-FILE", file.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); + } add_mhd_last_modified (r, archive_entry_mtime(e)); if (verbose > 1) obatched(clog) << "serving archive " << b_source0 << " file " << b_source1 << endl; 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