Skip to content

Commit

Permalink
Truncated errors now
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Feb 5, 2024
1 parent 72a9afc commit bdcf109
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions rc-zip-sync/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ fn check_case<F: HasCursor>(test: &Case, archive: Result<SyncArchive<'_, F>, Err
};

for file in &test.files {
tracing::info!("checking file {}", file.name);
let entry = archive
.by_name(file.name)
.unwrap_or_else(|| panic!("entry {} should exist", file.name));

tracing::info!("got entry for {}", file.name);
corpus::check_file_against(file, &entry, &entry.bytes().unwrap()[..])
}
}
Expand Down
9 changes: 5 additions & 4 deletions rc-zip/src/parse/local_headers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;

use crate::{
encoding::Encoding,
encoding::{detect_utf8, Encoding},
error::{Error, FormatError, UnsupportedError},
parse::{Method, MsdosTimestamp, Version},
};
Expand Down Expand Up @@ -122,18 +122,19 @@ impl<'a> LocalFileHeader<'a> {
self.flags & 0b1000 != 0
}

///
/// Converts the local file header into an entry.
pub fn as_entry(&self) -> Result<Entry, Error> {
// see APPNOTE 4.4.4: Bit 11 is the language encoding flag (EFS)
let has_utf8_flag = self.flags & 0x800 == 0;
let encoding = if has_utf8_flag {
let encoding = if has_utf8_flag && detect_utf8(&self.name[..]).0 {
Encoding::Utf8
} else {
Encoding::Cp437
};
let name = encoding.decode(&self.name[..])?;

let mut entry = Entry {
name: encoding.decode(&self.name[..])?,
name,
method: self.method,
comment: Default::default(),
modified: self.modified.to_datetime().unwrap_or_else(zero_datetime),
Expand Down

0 comments on commit bdcf109

Please sign in to comment.