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

Add support for outputting zip files with no data descriptors #337

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

chenxiaolong
Copy link
Owner

This commit adds a new --zip-mode parameter to avbroot ota patch to control whether the patched OTA zip is written with data descriptors or not. By default, the streaming mode is used, which matches the current behavior where the zip is hashed for signing as it is being written. The new seekable 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

@chenxiaolong chenxiaolong self-assigned this Aug 20, 2024
@chenxiaolong chenxiaolong mentioned this pull request Aug 20, 2024
This commit adds a new `--zip-mode` parameter to `avbroot ota patch` to
control whether the patched OTA zip is written with data descriptors or
not. By default, the `streaming` mode is used, which matches the current
behavior where the zip is hashed for signing as it is being written. The
new `seekable` 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

Signed-off-by: Andrew Gunnerson <[email protected]>
chenxiaolong added a commit that referenced this pull request Aug 21, 2024
Signed-off-by: Andrew Gunnerson <[email protected]>
@chenxiaolong chenxiaolong merged commit 7113fb3 into master Aug 21, 2024
5 checks passed
@chenxiaolong chenxiaolong deleted the seekable branch August 21, 2024 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant