Add support for outputting zip files with no data descriptors #337
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds a new
--zip-mode
parameter toavbroot ota patch
to control whether the patched OTA zip is written with data descriptors or not. By default, thestreaming
mode is used, which matches the current behavior where the zip is hashed for signing as it is being written. The newseekable
mode fully writes the zip before rereading it to hash the contents.The new mode is useful for devices with broken zip parsers that fail to properly handle data descriptors.
All of the end-to-end tests have been duplicated to test both modes.
Adding the seekable mode necessitated a couple other changes:
BufWriter is no longer used. Type erasure is very painful in Rust, so we need to keep the writer types the same for both the streaming and seekable modes. BufWriter is unusable in the seekable mode because we need to be able to read back what was written, which isn't supported.
HolePunchingWriter has been removed. It was a simple way to produce sparse files by seeking whenever a write buffer consists fully of zeros. When combined with BufWriter, there was previously never a situation where this was undesirable. However, with the new seekable mode and the zip library's pattern of writing one field at a time, the final 2 zero bytes (representing an empty archive comment) is never written and the file size is not increased either.
Removing this is not a big deal since we no longer use stripped OTAs for the end-to-end tests. Those were really the only OTAs that benefitted from sparse files. A real OTA has very few zero bytes due to compression.
Issue: #328