Selaa lähdekoodia

LibArchive: Pass along errors from Tar header checksum validation

Tim Schumacher 2 vuotta sitten
vanhempi
commit
cb48b9bc30

+ 4 - 7
Userland/Libraries/LibArchive/TarStream.cpp

@@ -94,8 +94,8 @@ ErrorOr<void> TarInputStream::load_next_header()
     if (header_span.size() != sizeof(m_header))
         return Error::from_string_literal("Failed to read the entire header");
 
-    if (!valid())
-        return Error::from_string_literal("Header is not valid");
+    if (!TRY(valid()))
+        return Error::from_string_literal("Header has an invalid magic or checksum");
 
     // Discard the rest of the header block.
     TRY(m_stream->discard(block_size - sizeof(TarFileHeader)));
@@ -103,7 +103,7 @@ ErrorOr<void> TarInputStream::load_next_header()
     return {};
 }
 
-bool TarInputStream::valid() const
+ErrorOr<bool> TarInputStream::valid() const
 {
     auto const header_magic = header().magic();
     auto const header_version = header().version();
@@ -114,10 +114,7 @@ bool TarInputStream::valid() const
         return false;
 
     // POSIX.1-1988 tar does not have magic numbers, so we also need to verify the header checksum.
-    if (header().checksum().is_error())
-        return false;
-
-    return header().checksum().release_value() == header().expected_checksum();
+    return TRY(header().checksum()) == header().expected_checksum();
 }
 
 TarFileStream TarInputStream::file_contents()

+ 1 - 1
Userland/Libraries/LibArchive/TarStream.h

@@ -36,7 +36,7 @@ public:
     static ErrorOr<NonnullOwnPtr<TarInputStream>> construct(NonnullOwnPtr<Core::Stream::Stream>);
     ErrorOr<void> advance();
     bool finished() const { return m_stream->is_eof(); }
-    bool valid() const;
+    ErrorOr<bool> valid() const;
     TarFileHeader const& header() const { return m_header; }
     TarFileStream file_contents();