Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate filename, but what? #127

Open
frederikhors opened this issue May 15, 2024 · 8 comments · May be fixed by #277
Open

Duplicate filename, but what? #127

frederikhors opened this issue May 15, 2024 · 8 comments · May be fixed by #277
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@frederikhors
Copy link

I'm getting this error:

invalid Zip archive: Duplicate filename

but I cannot understand what is the file duplicated.

Is it possible to write the filename in the error?

@frederikhors frederikhors added the bug Something isn't working label May 15, 2024
@Pr0methean Pr0methean added the good first issue Good for newcomers label May 16, 2024
@Pr0methean
Copy link
Member

Pr0methean commented May 16, 2024

Fixing this will require that ZipError::InvalidArchive wrap a Cow<'static, str> rather than &'static str so that it can include a message generated at runtime, but without the overhead of allocating a string at runtime when it's not doing so.

@Pr0methean
Copy link
Member

Started work on a solution, but running into some macro errors that I either don't know or have forgotten how to solve.

@Pr0methean Pr0methean added the help wanted Extra attention is needed label May 16, 2024
@Rapptz
Copy link

Rapptz commented Aug 2, 2024

I ran into this issue as well. I'd really like to know what the duplicate is or how to avoid this.

Started work on a solution, but running into some macro errors that I either don't know or have forgotten how to solve.

I think the error you're getting is because you're expanding the argument list into a tuple rather than just letting it expand as arguments to the format! macro.

@Bogay
Copy link

Bogay commented Jan 5, 2025

Hi, I'm interested in solving this. After spending some time digging through the code in commit 4185739, I believe that I can solve the macro issue. If it's OK, I would like to open a PR. However, there are a few things I want to address:

  1. I found that besides InvalidArchive, other error variants are also added more fields. But in this commit they are not used. Should I include them in my PR to add more context to other types of error?

zip2/src/result.rs

Lines 17 to 38 in 4185739

/// Error type for Zip
#[derive(Debug, Display, Error)]
#[non_exhaustive]
pub enum ZipError {
/// i/o error: {0}
Io(#[from] io::Error),
/// invalid Zip archive: {0}
InvalidArchive(Cow<'static, str>),
/// unsupported Zip archive: {0}
UnsupportedArchive(Cow<'static, str>),
/// specified file not found in archive
FileNotFound(Box<str>),
/// The password provided is incorrect
InvalidPassword {
filename: Box<str>,
password: Option<Box<str>>
},
}

  1. The invalid! macro returns ZipResult, so it can't be used in functions such as Option::ok_or. Following code can't be compiled because it needs a ZipError

zip2/src/read.rs

Lines 410 to 417 in 4185739

new_files.values_mut().try_for_each(|f| {
/* This is probably the only really important thing to change. */
f.header_start = f.header_start.checked_add(new_initial_header_start).ok_or(
invalid!("new header start from merge would have been {} bytes, which is too large",
f.header_start as u128 + new_initial_header_start as u128))?;
/* This is only ever used internally to cache metadata lookups (it's not part of the
* zip spec), and 0 is the sentinel value. */
f.central_header_start = 0;

  1. There are some const InvalidArchive and after it wraps a Cow these statements should be ZipError::InvalidArchive(Cow::Borrow("...")). Maybe I can adjust the invalid! macro to make it const? or another const fn to create a const error literal.

zip2/src/spec.rs

Lines 266 to 267 in e074e09

const WRONG_MAGIC_ERROR: ZipError =
ZipError::InvalidArchive("Invalid digital signature header");

@Pr0methean
Copy link
Member

Sure, a PR would be great. Do whatever makes the invalid! macro as widely usable as possible, and add a second macro if you need; we can always refactor later.

@Bogay Bogay linked a pull request Jan 13, 2025 that will close this issue
@Bogay
Copy link

Bogay commented Jan 13, 2025

I've opened a draft PR, but I noticed an issue with the CI. Currently, the CI only runs fmt and check against zip2, so the code inside fuzz_write and fuzz_read isn't formatted. This results in some unrelated style changes appearing in my PR. Would it make sense to add these checks to the CI in a separate PR first?

@Pr0methean
Copy link
Member

Sure, sounds good.

@Bogay
Copy link

Bogay commented Jan 24, 2025

PR opened (#283). I ran into some clippy problems, so it took longer than expected...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants