public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: fche@redhat.com
Cc: elfutils-devel@sourceware.org, Aaron Merey <amerey@redhat.com>
Subject: [PATCH] debuginfod: ensure X-DEBUGINFOD-SIZE contains file size
Date: Mon, 25 Apr 2022 11:14:37 -0400	[thread overview]
Message-ID: <20220425151437.56310-1-amerey@redhat.com> (raw)
In-Reply-To: <20220422232731.GF23969@redhat.com>

Hi Frank,

On Fri, Apr 22, 2022 at 7:27 PM Frank Ch. Eigler <fche@redhat.com> 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 <amerey@redhat.com>
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 <amerey@redhat.com>
---
 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
-- 
2.35.1


      reply	other threads:[~2022-04-25 15:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 22:26 [PATCH 2/2] " Aaron Merey
2022-04-22 22:31 ` Aaron Merey
2022-04-22 23:27 ` Frank Ch. Eigler
2022-04-25 15:14   ` Aaron Merey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220425151437.56310-1-amerey@redhat.com \
    --to=amerey@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=fche@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).