Commit graph

738 commits

Author SHA1 Message Date
Marli Frost
7fe65607f3 update aes to 0.8
(hazard): The changelog in aes doesn't indicate any change in behaviour,
and I have assumed the new APIs work identically
2023-02-12 11:17:54 +00:00
Kyle Bloom
1aa3710aff Remove redundant tests 2023-02-02 08:56:19 +00:00
Marli Frost
c4c6ec9e7c fix: clippy 2023-02-01 18:03:03 +00:00
Marli Frost
d06d4b295f refactor: move the new ZipStreamReader API to the unstable module 2023-02-01 17:55:07 +00:00
Marli Frost
1eb491e96e fix: clippy lint 2023-02-01 17:39:10 +00:00
Jiahao XU
e322842bfd Fix clippy warning in stream.rs:85
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
f97f017d99 Rm read::stream::test::zip_contents
As streaming mode cannot calculate central_header_start.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
89ff32d93b Rm infesible guarantee in ZipStreamVisitor::visit_additional_metadata
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
ef1846e121 Rm stream::tests::zip64_with_leading_junk
As in streaming mode, there is no way to ignore the leading junk.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
b944bee72d Add unit tests for mod read::streams
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
c6fe396b56 Impl ZipStreamFileMetadata::is_{dir, file}
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
d858994e1e Add guarantee for ZipStreamVisitor::visit_additional_metadata
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
8f7c43c227 Rm unnecessary p.exist() check in ZipStreamReader::extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
5b6d9557c6 Impl ZipStreamReader::extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
42e2865ccb derive(Debug) for ZipStreamFileMetadata
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
02c3699be2 Impl new mod read::stream
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
16753209af Refactor: Extract ZipFileData::unix_mode
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
a614d1f226 Refactor: Extract ZipFileData::enclosed_name
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:33:35 +00:00
Jiahao XU
08c2e76705 Fix param order in central_header_to_zip_file_inner
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:31:12 +00:00
Jiahao XU
e99c15471c Mv central header parsing to central_header_to_zip_file
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:31:12 +00:00
Jiahao XU
57440efa16 Refactor: Extract new fn central_header_to_zip_file_inner
that does not require `reader` to implement `io::Seek`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-02-01 17:31:12 +00:00
Marli Frost
0a09253896 docs: clarify how to use the add_directory API
closes #323
2023-02-01 17:23:53 +00:00
Marli Frost
42eabc9e33 fix: update references to old from_time API 2023-02-01 14:01:53 +00:00
Kyle Bloom
ccd20c118e fix: Unused import with time feature 2023-02-01 13:58:15 +00:00
Kyle Bloom
ab2800b4d8 chore: Move use for TryInto to top 2023-02-01 13:58:15 +00:00
Kyle Bloom
c2adaf7ee0 fix: Use try into implementation for from_time 2023-02-01 13:58:15 +00:00
Kyle Bloom
3f770178ec fix: Change error type to unit-like struct 2023-02-01 13:58:15 +00:00
Kyle Bloom
5726a07a76 feat: Move from_time to try_from
Moves from_time function to TryFrom<OffsetDateTime>
2023-02-01 13:58:15 +00:00
Kyle Bloom
9a577d09fb
Merge branch 'zip-rs:master' into fix-clippy-issues 2023-02-01 10:07:13 +00:00
Kyle Bloom
503eda67c3 fix: Clippy should implement trait 2023-01-31 17:36:06 +00:00
Kyle Bloom
03f5009c34 fix: Clippy uninlined format args 2023-01-31 17:29:34 +00:00
Mikael Pettersson
3fc54cf68c feat: Detect insufficient Dir record size
- Per zip spec 4.4.1.4 (https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)
- If a CentralDirectoryEnd record field cannot hold the
  required data, a ZIP64 record must exist and the
  field will be set to -1(0xFFFF || 0xFFFFFFFF)
- Previously these archives were incorrectly detected as multi-disk
2023-01-30 11:13:01 +01:00
jkasari
7b83591f26 Add units to the size documentation.
The documentation did not list what it meant by "size". I changed it to
specify that it is returning the size in bytes.
2023-01-19 18:55:42 -08:00
Wyatt Herkamp
efd7f934ca Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/read.rs
2022-10-13 07:53:55 -04:00
Wyatt Herkamp
1c5cd4ffda Fixed new Clippy Warnings 2022-10-13 07:51:02 -04:00
Wyatt Herkamp
d59adf0990 Fixed new Clippy Warnings 2022-10-13 07:44:25 -04:00
Wyatt Herkamp
24caeaac27 Make github ci use 1.59 for time depend and fix two clippy warnings 2022-10-13 07:44:21 -04:00
Wyatt Herkamp
89e84e1032 Fixed new Clippy Warnings 2022-09-27 13:30:55 -04:00
Wyatt Herkamp
13084ef732 Make github ci use 1.59 for time depend and fix two clippy warnings 2022-09-12 18:53:15 -04:00
Jiahao XU
80005fd2e1
Optimize inner of ZipArchive::extract
Rm generics in `inner`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-20 23:54:04 +10:00
Jiahao XU
6402eb0d22
Avoid dup monomorphization in ZipArchive::extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-20 23:50:34 +10:00
Jiahao XU
199796cbbf
Rm unnecessary p.exist() in ZipArchive::extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-20 23:48:48 +10:00
Dirk Stolle
e3d8f47708 Fix a few typos 2022-05-01 00:39:24 +02:00
Nick Babcock
03613cb56e Fix capacity overflow on invalid zips reads
Preemptively allocating structures with the number of reported files can
lead to trouble as an invalid zip can still have a valid central
directory end that is fed into a `with_capacity` causing it to overflow.

This commit introduces a heuristic that will use the reported number of
files as long as the number is less than the cde offset.

Benchmarks were unaffected by this change.
2022-04-25 21:01:56 -05:00
Gregory Szorc
46c2ae88d4 Implement support for writing symlinks
The primary goal of this commit is to enable this library to emit
zip archives with symlinks while minimizing the surface area of the
change to hopefully enable the PR to merge with minimal controversy.

Today, it isn't possible to write symlinks with this library because
there's no way to preserve the upper S_IFMT bits in the file mode
bits because:

* There's no way to set FileOptions.permissions with the S_IFLNK bits
  set (FileOptions.unix_permissions() throws away bits beyond 0o777).
* Existing APIs for starting a "typed" (e.g. file or directory) entry
  automatically set the S_IFMT bits and could conflict with bits
  set on FileOptions.permissions.
* The low-level, generic start_entry() function isn't public.

When implementing this, I initially added a `FileOptions.unix_mode()`
function to allow setting all 16 bits in the eventual external
attributes u32. However, I quickly realized this wouldn't be enough
because APIs like start_file() do things like `|= 0o100000`. So if
we went this route, we'd need to make consumers of
FileOptions.permissions aware of when they should or shouldn't touch
the high bits beyond 0o777.

I briefly thought about making FileOptions.permissions an enum with
a variant to allow the st_mode bits to sail through unmodified. But
this change seemed overly invasive, low level, and not very
user-friendly.

So the approach I decided on was to define a new add_symlink() API.
It follows the pattern of add_directory() and provides an easy-to-use
and opionated API around the addition of a special file type.

I purposefully chose to not implement reading or extraction support
for symlinks because a) I don't need the feature at the moment
b) implementing symlink extraction in a way that works reliably on all
platforms and doesn't have security issues is hard. I figured it was
best to limit the scope of this change so this PR stands a good chance
of being merged.

Partially implements #77.
2022-04-12 10:58:24 -07:00
Pieter-Jan Briers
621971f078 Use some ::with_capacity when reading zip file.
Now with a proper benchmark
2022-04-11 16:17:20 +02:00
Pieter-Jan Briers
6b5628bef4 Use Seek.stream_position instead of seek(0).
BufReader can cache the result of stream_position() so it's fast, whereas seek(0) discards the read buffer and passes through straight to the OS. This drastically worsens the efficiency of loading performance when using BufReader (or anything else to avoid all these tiny reads going straight to the kernel).
2022-04-11 14:30:27 +02:00
messense
2d0d1d2990
Fix build for armv5te target 2022-04-02 10:37:36 +08:00
Rouven Spreckels
9a32d129ff Fix build with --no-default-features. 2022-03-28 11:43:25 +02:00
Alexander Zaitsev
77294fd3ce
Revert "Merge pull request #290 from aweinstock314/more-spec-structs"
This reverts commit a1da6860ea, reversing
changes made to 574bb3df17.
2022-03-26 14:13:50 +03:00