Skip to content

Commit

Permalink
Read sizes from the central directory if they aren't present in the l…
Browse files Browse the repository at this point in the history
…ocal header

PiperOrigin-RevId: 644428764
Change-Id: Ie320016c301721e9ec03032a1dbf8dc9193abab6
  • Loading branch information
cushon authored and Copybara-Service committed Jun 18, 2024
1 parent fbcd70e commit f104ff9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/tools/singlejar/combiners.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool Concatenator::Merge(const CDH *cdh, const LH *lh) {
}
CreateBuffer();
if (Z_NO_COMPRESSION == lh->compression_method()) {
buffer_->ReadEntryContents(lh);
buffer_->ReadEntryContents(cdh, lh);
} else if (Z_DEFLATED == lh->compression_method()) {
if (!inflater_) {
inflater_.reset(new Inflater());
Expand Down Expand Up @@ -138,7 +138,7 @@ bool XmlCombiner::Merge(const CDH *cdh, const LH *lh) {
// and remove the start and end tags if they are present.
TransientBytes bytes_;
if (Z_NO_COMPRESSION == lh->compression_method()) {
bytes_.ReadEntryContents(lh);
bytes_.ReadEntryContents(cdh, lh);
} else if (Z_DEFLATED == lh->compression_method()) {
if (!inflater_) {
inflater_.reset(new Inflater());
Expand Down
2 changes: 1 addition & 1 deletion src/tools/singlejar/desugar_checking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool Java8DesugarDepsChecker::Merge(const CDH *cdh, const LH *lh) {
// Throw away anything previously read, no need to concatenate
buffer_.reset(new TransientBytes());
if (Z_NO_COMPRESSION == lh->compression_method()) {
buffer_->ReadEntryContents(lh);
buffer_->ReadEntryContents(cdh, lh);
} else if (Z_DEFLATED == lh->compression_method()) {
if (!inflater_) {
inflater_.reset(new Inflater());
Expand Down
10 changes: 8 additions & 2 deletions src/tools/singlejar/transient_bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ class TransientBytes {
}

// Appends the contents of the uncompressed Zip entry.
void ReadEntryContents(const LH *lh) {
Append(lh->data(), lh->uncompressed_file_size());
void ReadEntryContents(const CDH *cdh, const LH *lh) {
uint64_t uncompressed_file_size;
if (cdh->no_size_in_local_header()) {
uncompressed_file_size = cdh->uncompressed_file_size();
} else {
uncompressed_file_size = lh->uncompressed_file_size();
}
Append(lh->data(), uncompressed_file_size);
}

// Appends the contents of the compressed Zip entry. Resets the inflater
Expand Down
2 changes: 1 addition & 1 deletion src/tools/singlejar/transient_bytes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST_F(TransientBytesTest, ReadEntryContents) {
continue;
}
ASSERT_EQ(Z_NO_COMPRESSION, lh->compression_method());
transient_bytes_->ReadEntryContents(lh);
transient_bytes_->ReadEntryContents(cdh, lh);
ASSERT_EQ(cdh->uncompressed_file_size(), transient_bytes_->data_size());
struct Sink {
Sink(const LH *lh)
Expand Down

0 comments on commit f104ff9

Please sign in to comment.