Skip to content

Commit

Permalink
make the handling of pax extensions more general
Browse files Browse the repository at this point in the history
Signed-off-by: Qinqi Qu <quqinqi@linux.alibaba.com>
  • Loading branch information
adamqqqplay committed Jul 14, 2023
1 parent 06de2ea commit 61c726b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a, R: Read> Iterator for Entries<'a, R> {
impl<'a> EntriesFields<'a> {
fn next_entry_raw(
&mut self,
pax_size: Option<u64>,
pax_extensions: &Option<Vec<u8>>,
) -> io::Result<Option<Entry<'a, io::Empty>>> {
let mut header = Header::new_old();
let mut header_pos = self.next;
Expand Down Expand Up @@ -315,6 +315,11 @@ impl<'a> EntriesFields<'a> {
return Err(other("archive header checksum mismatch"));
}

let mut pax_size: Option<u64> = None;
if let Some(pax_extensions_ref) = &pax_extensions {
pax_size = pax_extensions_value(pax_extensions_ref, "size");
}

let file_pos = self.next;
let mut size = header.entry_size()?;
if size == 0 {
Expand Down Expand Up @@ -354,17 +359,16 @@ impl<'a> EntriesFields<'a> {

fn next_entry(&mut self) -> io::Result<Option<Entry<'a, io::Empty>>> {
if self.raw {
return self.next_entry_raw(None);
return self.next_entry_raw(&None);
}

let mut gnu_longname = None;
let mut gnu_longlink = None;
let mut pax_extensions = None;
let mut pax_size = None;
let mut processed = 0;
loop {
processed += 1;
let entry = match self.next_entry_raw(pax_size)? {
let entry = match self.next_entry_raw(&pax_extensions)? {
Some(entry) => entry,
None if processed > 1 => {
return Err(other(
Expand Down Expand Up @@ -408,9 +412,6 @@ impl<'a> EntriesFields<'a> {
));
}
pax_extensions = Some(EntryFields::from(entry).read_all()?);
if let Some(pax_extensions_ref) = &pax_extensions {
pax_size = pax_extensions_value(pax_extensions_ref,"size");
}
continue;
}

Expand Down

0 comments on commit 61c726b

Please sign in to comment.