Commit Graph

1375 Commits

Author SHA1 Message Date
Robert Haines 14b63f68db Ensure `File.open_buffer` doesn't rewrite unchanged data. 2021-11-30 22:22:37 +00:00
Robert Haines f5e19db273 Add a 100,000 file zip to test `count_entries`. 2021-11-20 20:02:47 +00:00
Robert Haines 22e47641e6 Add `File::count_entries`.
This method provides a short cut to finding out how many entries are in
an archive by reading this number directly from the central directory,
and not iterating through the entire set of entries.
2021-11-20 10:53:00 +00:00
Robert Haines 3db1eff1e3 Add `CentralDirectory#count_entries`.
This method gets the number of entries from a zip archive without
loading all of the individual entries.
2021-11-20 10:50:55 +00:00
Robert Haines 6a516fb0b1 Factor out reading EOCD records.
This allows for reading the EOCD records without then automatically
reading all of the entry data as well, so that we can do other things
faster, like provide the number of entries in an archive.
2021-11-20 10:36:32 +00:00
Robert Haines 765cb316f1 Fix reading unknown extra fields.
When loading extra fields from both the central directory and local headers,
unknown fields were not merged correctly. They were being appended, which
means that we end up with the two versions stuck together - in some
cases duplicating the field completely.

This broke all kinds of things (like calculating the size of a local
header) in subtle ways.

This commit fixes this by implementing a new `Unknown` extra field type,
and making sure that when reading local and central extra fields they
are stored and preserved correctly. We cannot assume the unknown fields
use the same data in the local and central headers.

Fixes #505.
2021-11-19 19:53:38 +00:00
Robert Haines f7cd692e15 Fix reading zip files with max length file comment.
If a zip file has a comment that is 65,535 characters long - which is a
valid length and the maximum allowable length - the initial read of the
archive fails to find the End of Central Directory Record and therefore
cannot read the rest of the file.

This commit fixes this by making sure that we look far enough back into
the file from the end to find the EoCDR. Test added to catch
regressions.

Fixes #508.
2021-11-19 19:35:36 +00:00
Robert Haines bc6523ec43 Unpick changes from v2.3.1. 2021-07-05 22:22:01 +01:00
Robert Haines c3b1e5d693 Pick changes from v2.3.1. 2021-07-03 13:45:22 +01:00
Robert Haines 54b7762c8f Don't silently alter zip files opened with `Zip::sort_entries`.
Fixes #329.
2021-06-30 23:18:59 +01:00
Yo Yehudi 322955c6b4 add research notice
so that contributors will be aware metrics are being gathered on this repo over the  next year.  If there's a better place to put this please let me know. :)
2021-06-28 13:18:45 +01:00
Robert Haines 66527ae10d Fix minor typo in `GPFBit3Error` message in `InputStream`. 2021-06-27 21:55:15 +01:00
Robert Haines 19e5f4a8ce Detect and raise GPFBit3Error in `InputStream.get_next_entry`.
We were previously trying to work out where the next entry would be,
even with GP bit 3 set, but the logic was flaky and cannot really be
correct given the data available. It's not expected behaviour, so raise
the error instead.

This means that we get rid of the incorrect `Entry.data_descriptor_size`
which was doing more harm than good.
2021-06-27 21:43:03 +01:00
Robert Haines 8071290ce6 Update and tidy up encryption tests. 2021-06-27 15:56:39 +01:00
Robert Haines 50dddca0be Update encrypted fixtures to remove data descriptors. 2021-06-27 15:54:08 +01:00
Robert Haines bb237aaa08 Update authors in gemspec to reflect current maintainers. 2021-06-27 11:47:31 +01:00
Robert Haines f005ca2864 Update the list of files packaged in the gemspec. 2021-06-27 11:30:09 +01:00
Robert Haines 81d95ad0a3 Minor gemspec formatting changes for space/readability. 2021-06-27 11:29:55 +01:00
Robert Haines 1fb74bd82f Don't mess with the library path in the gemspec. 2021-06-27 11:04:53 +01:00
Robert Haines 9fc12bf97b Add notes to the README and Changelog about the new API. 2021-06-27 10:20:11 +01:00
Robert Haines aa646ef827 Use named params for `InputStream`. 2021-06-27 10:20:11 +01:00
Robert Haines f75eb61578 Use named parameters for `File#get_output_stream`. 2021-06-27 10:20:11 +01:00
Robert Haines debc9fda91 Use named parameters for `File::split`. 2021-06-27 10:20:11 +01:00
Robert Haines f033ae760d Use named parameters for `File::new`.
This is a breaking change, but now is the time to do this as we've
already done the same for `Entry::new`.
2021-06-27 10:20:11 +01:00
Robert Haines e1e1cab39c Fix some non-writable `StringIO`s. 2021-06-27 10:20:11 +01:00
Robert Haines 659db85bff `open` and `write_buffer` in `OutputStream` use named params. 2021-06-27 10:20:11 +01:00
Robert Haines 7ae90be63e Fix Style/OptionalBooleanParameter in `OutputStream`. 2021-06-27 10:20:11 +01:00
Robert Haines e7f0aba5ff Fix Style/OptionalBooleanParameter cop in `Entry`.
Just an internal API so safe, and makes things a lot neater.
2021-06-27 10:20:11 +01:00
Yuya.Nishida f76cef90f7 Remove newer duplicated line 2021-06-26 22:53:37 +01:00
Robert Haines 8699e356d4 Improve documentation for `File.glob`.
Closes #338.
2021-06-26 20:04:17 +01:00
Robert Haines a301d68eeb Raise an error if entry names exceed 65,535 characters.
Fixes #247.
2021-06-26 19:21:07 +01:00
Robert Haines 49e313629e Remove the `ZipXError` v1 legacy classes. 2021-06-26 17:39:25 +01:00
Robert Haines e000552deb Raise an error on reading a split archive with `InputStream`.
Fixes #349.
2021-06-26 12:39:08 +01:00
Robert Haines 193507b15a Adjust Layout/LineLength cop to 100 characters.
We'll get the line length down in stages...
2021-06-25 22:31:34 +01:00
Robert Haines de6ec15610 Update Changelog. 2021-06-25 17:54:30 +01:00
Robert Haines 84b3e8c644 Ensure `InputStream` raises `GPFBit3Error` for OSX Archive files.
Fixes #493.
2021-06-25 17:53:18 +01:00
Robert Haines 78565db40c Simplify `InputStream.open_entry`.
Also ensure `@complete_entry` is initialized!
2021-06-25 17:53:18 +01:00
Robert Haines c29297c0b8 Add a test to ensure `InputStream` raises `GPFBit3Error`. 2021-06-25 17:53:18 +01:00
Robert Haines ac053bd787 Improve documentation and error messages for `InputStream`.
Closes #196.
2021-06-25 16:58:01 +01:00
Robert Haines 1183607ea1 Flush buffered `OutputStream` on close.
Fixes #265.
2021-06-23 22:24:44 +01:00
Robert Haines a2a14c2cd2 Fix Style/RedundantRegexpEscape cop. 2021-06-18 16:31:23 +01:00
Robert Haines f1e8c2fc9d Fix Style/StringConcatenation cop. 2021-06-18 16:10:57 +01:00
Robert Haines f66a15a85d Update rubocop config. 2021-06-18 16:00:57 +01:00
Robert Haines 71f2c90b20 Test that a corrupted cdir entry is caught. 2021-06-18 12:08:31 +01:00
Robert Haines 75386f8db6 Remove now redundant `IOizeString` module. 2021-06-18 11:50:07 +01:00
Robert Haines afe1892208 Fix a mis-firing CentralDirectory test.
`test_read_from_truncated_zip_file` was not testing what it thought it
was. It was testing whether we caught an out-of-bounds cdir offset, not
whether we caught a corrupted cdir entry.

This commit embraces the actual behaviour and tests that we catch an
out-of-bounds error for both standard `IO`s and `StringIO`s.
2021-06-18 11:44:58 +01:00
Robert Haines bf3ae2ad76 Improve some entry header tests.
Use `StringIO` instead of the custom `IOizeString` code in the
test_helper.

Also test both versions (class and instance) of the `Entry` APIs.
2021-06-18 11:11:11 +01:00
Robert Haines 750c474610 Update Changelog. 2021-06-12 16:31:50 +01:00
Robert Haines 21ba82c67c Move the split signature to the constants file. 2021-06-12 16:29:25 +01:00
Robert Haines 80382135e5 Tidy up some of the file split code. 2021-06-12 16:29:25 +01:00