26 Commits
Author SHA1 Message Date
Kelvin Zhang 92fb83025d Allow bootable/deprecated-ota to use bsdiff
non-AB code will be moved to bootable/deprecated-ota , so add necessary
visibility rules.

Test: th
Bug: 324360816
Change-Id: Icc56f020ab1470c797cad0d62e4bd027fcfcd703
2024-04-05 09:41:53 -07:00
Kelvin Zhang 67386a2f62 Make bsdiff available in recovery
Change-Id: I9e96d475a52648e885925502be5801926d2764e3
2021-12-20 19:47:02 -08:00
Julien Desprez f57f693dd7 Update bsdiff_unittest to really work host-side
bsdiff_unittest is marked host_supported:true but use
a AndroidTest.xml config that can only work for device.

Deleting the explict config to rely on the auto-gen ones.
Adding unit_tests:true to run in presubmit

Change-Id: Ia3a23149ccdc2efa2c880436e30fcff4acf9ddd9
Test: presubmit, atest bsdiff_unittest --host
Bug: 179092189
2021-02-07 21:32:11 +00:00
Bob Badour 5489e95ad8 Add LOCAL_LICENSE_KINDS to external/bsdiff
Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: Ic407d90ef0cf787a41786d3775653c5a1e831df8
2021-01-21 17:10:33 -08:00
David Anderson 6caee521ee Allow libsnapshot to link to bsdiff.
Bug: 1378463
Test: m vab_convert_payload
Change-Id: I8f36ba5bc9b054c2626abf3ed475864f34d40d25
2020-08-05 17:31:04 -07:00
Bill Peckham 590b1fad39 Restrict visibility of libraries that are newly vendor_available: true.
As part of fixing b/68319577, some libraries were made vendor_available: true.
To minimize new dependencies from vendor on these libraries, this change
restricts the visibility of the libraries to only the framework projects that
currently use them.

Bug: 141649008
Test: Targets build successfully.
Change-Id: I675f5d74bb6d1bf06ae5ebd8ae5bfdd5653485a3
2019-10-17 18:09:55 -07:00
Bill Peckham 64263b787c Moving recovery resources from /system to /vendor
This change is part of a topic that moves the recovery resources from the
system partition to the vendor partition, if it exists, or the vendor directory
on the system partition otherwise. The recovery resources are moving from the
system image to the vendor partition so that a single system image may be used
with either an A/B or a non-A/B vendor image. The topic removes a delta in the
system image that prevented such reuse in the past.

The recovery resources that are moving are involved with updating the recovery
partition after an update. In a non-A/B configuration, the system boots from
the recovery partition, updates the other partitions (system, vendor, etc.)
Then, the next time the system boots normally, a script updates the recovery
partition (if necessary). This script, the executables it invokes, and the data
files that it uses were previously on the system partition. The resources that
are moving include the following.

* install-recovery.sh
* applypatch
* recovery-resource.dat (if present)
* recovery-from-boot.p (if present)

This change supports making a direct or transitive dependency of the applypatch
executable available to applypatch, which is now on vendor.

Bug: 68319577
Test: Ensure that recovery partition is updated correctly.
Change-Id: I66059c3cfe2f65eca990b29609fd2c5f52e17266
2019-09-19 17:10:17 +00:00
Tao Bao 1c1bce9a48 Don't build bspatch executable for Android target.
All the users should use libbspatch instead. The host rule stays for
easier testing.

Test: m checkbuild
Change-Id: I4a23a7383ebda8b7bf61508ffe3cf47cc573ad29
2019-01-10 18:39:56 -08:00
Dan Willemsen 141f70a9bc Mark libbspatch as recovery_available for update_engine_sideload
Test: build update_engine_sideload
Change-Id: I75fce6c7da055e6e7a08d98530de15536bc1b964
2018-10-23 13:44:38 -07:00
Alex Deymo 338f340c14 Fix brotli decompressor interface usage when reading past the end.
Bortli returns BROTLI_DECODER_RESULT_SUCCESS only when the whole file
was already decompressed, otherwise it will keep returning
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT until enough output space was
provided overall.

This patch fixes the infinite loop caused when trying to decompress
more bytes than available in the uncompressed stream.

Bug: None
Test: Added unittests.
Change-Id: I3a17dc2e9a0b90659161a9315ce27cdb5e90a894
2018-03-26 13:54:46 +02:00
Alex Deymo 64d5cd8065 Fix infinite loop when providing a partial input bz2 stream.
The bz2 decompressor expects to read from the input until there's enough
output produced. This patch makes the read fail if we get stuck without
making any progress in the decompression.

Bug: chromium:818174
Test: Added unittest.
Change-Id: Iaee8a2184ec1c5a7dbbe261ec77a39ce247965a3
2018-03-12 20:06:27 +01:00
Tianjie Xu 1f1cdb2b6b Add an argument parser in bsdiff
Add a parser of format, type and quality in the bsdiff main function.
This allow the bsdiff binary to choose between the BSDFF40|BSDF2 patch
format and compress the patch with desired algorithms.

Bug: 34220646
Test: unittest pass; generate brotli compressed patches with bsdiff
binary
Change-Id: Ia4f7941e4eca7e6047e2749315127d1cf4a988ee
2018-01-18 12:32:09 -08:00
Tianjie Xu 18480eb706 Implement a simple logger for bsdiff
The logger supports LOG & PLOG. It also adds a std::endl at the end of
the stream so that we don't need to add it manually at the callsite.

Test: run bsdiff and check the logs.
Change-Id: Ice94902a501532ceaeb480c3576e752e435cab70
2017-11-30 12:28:06 -08:00
Tianjie Xu 4d10c3efd7 Add a brotli decompressor in bsdiff
This CL implements the brotli decompressor used in PatchReader. Also
extract the CompressorType and patch's MagicHeader to a common header file.

Bug: 34220646
Test: Run bsdiff/bspatch with brotli compressor/decompressor over a list
of files from angler's system image.

Change-Id: I76e11168075c6481490ffbc025ec4ca81e828732
2017-11-14 14:36:55 -08:00
Alex Deymo 710b3daa48 Implement Play Store's "endsley" patching format generator.
Android's Play Store uses, among other options, a bsdiff patch format
similar to Matthew Endsley's bsdiff implementation. The main difference
is that Play Store's version doesn't do any compression in the patch
format itself, but instead the compression is handled at a higher
level.

This CL introduces a new PatchWriterInterface derived class to write to
this (uncompressed) format.

See https://github.com/mendsley/bsdiff for the original implementation
of this format. See also Google's APK patch size estimator for more
information on the file-by-file format used by Play Store:
https://github.com/googlesamples/apk-patch-size-estimator

Bug: 67458097
Test: Added simple unittests for the generated files.

Change-Id: I3b048abf2220e2cb3af0a95e27efe1c0f241046a
2017-11-08 21:41:45 +01:00
Alex Deymo cb620cadee Remove the include/bsdiff export.
All clients now include "bsdiff/bsdiff.h" so no need for this export
path anymore.

Bug: None
Test: `make checkbuild`
Change-Id: I0cc7882a58905fcd276600ee2efa01620a7ab378
2017-11-02 20:19:41 +01:00
Tianjie Xu 1c26e2ed9b Add the brotli compressor for bsdiff
Add a new compressor interface; and the brotli compressor which is
similar to the existing bz2 one.

Also add a new CompressorType argument to PatchWriter's init function;
this allows us to choose the right compressor based on the input option
in the future.

Bug: 34220646
Test:  Run bsdiff/bspatch with brotli compressor/decompressor over a
list of files from angler's system image. Make succeeds.
Change-Id: Id9a3db2d7d051dcb751a1fc362f4c3b9226e878b
2017-10-31 11:37:45 -07:00
Alex Deymo 8a179e5e27 Expose the PatchWriter generator in the public API.
We want to expose the patch writers constructors in the public API
without necesarily exposing the internal details. For that, we use a
factory in the public API so callers can create the PatchWriters they
need.

We will extend this file with new patch formats.

Bug: 34220646
Test: Used this interface from the bsdiff_main.cc (see follow up CL).
Change-Id: I1f005f103886579eacf37b7d9767b713e066030c
2017-10-27 13:52:46 +02:00
Tianjie Xu 6528812247 Add an interface for bspatch reader
Add a wrapper class to separate the patch read from data stream
decompression. Therefore, bspatch will be able to process the patch
that is compressed with various tools.

Test: unittest pass
Change-Id: I5214e0451bde80366e8a70b960703afb2b2a7d97
2017-10-26 14:50:34 -07:00
Alex Deymo 48ad5ab76e Select SuffixArray size at runtime.
The suffix array is used to search for strings from the new file in the
old file. The size of each element of the suffix array must be big
enough to hold the length of the old file. In most of the cases we use,
if not all of them, the old file is smaller than 2 GiB, which allows to
use 32-bit integers for the suffix array.

The previous code decided whether to use 64-bit or 32-bit integers
based on the large-file surpport, even in 32-bit computers architectures
which would not work in those cases; and would also use twice as much
memory when constructing the suffix array of inputs smaller than 2 GiB.

This patch selects the suffix array size based on the input size,
effectively using half the memory in the most common case. This also
improves the runtime performance due to lower cache pressure.

As a side effect, this patch hides the suffix array implementation
details from the public interface. This removes the limitation where
the caller of libbsdiff and libbsdiff needed to be compiled with the
same large-file support flags; and also hides the dependency on
libdivsufsort from the public interface.

While doing so, instead of re-implementing the suffix array search
algorithm (which had a history of bugs and corner cases) we re-use the
one from libdivsufsort, adapted to the bsdiff algorithm use-case.

The result is about 40% faster when diffing 10MiB files, and the patch
size is within 0.1%, due to differences in the position selected
whenever more than one match is available.

Bug: 34220646
Test: Added unittests for the suffix array.

Change-Id: Ib9dc85a83bbf10157a3937c5687e5663ab0d20d5
2017-10-20 16:37:51 +02:00
Alex Deymo e1140a25f4 New SplitPatchWriter to split a bsdiff patch into multiple ones.
This new PatchWriterInterface derived class allows to split the
output patch of a bsdiff run into multiple files of a fixed new file
size. This allows to split long operations with minimal loss of patch
size due to splitting the compression blocks. For large enough new file
sections, this patch size reduction should be minimal.

Bug: 34220646
Test: Added unittests.
Change-Id: Ib90fddd5c55a38c87ce396f2792aa558ecd07b22
2017-10-11 13:08:47 +02:00
Alex Deymo 68c0e7f206 Reduce PatchWriterInterface functionality.
The recently introduced PatchWriterInterface had both the patch file
format logic and the diff/extra streams selection from the control
entries. While this simplifies the bsdiff main algorithm and makes
invalid usages of the BsdiffPatchWriter evident, writing alternative
PatchWriterInterface classes required to replicate the diff/extra
stream selection logic.

This patch splits out the diff/extra stream generation and all the
checks around those to a new helper class DiffEncoder. The public
interface PatchWriterInterface now has two methods to accept the diff
and extra stream data, and does not compute them.

Bug: 34220646
Test: Added unittests. Ran bsdiff on some pairs of files obtaining the same result as before.
Change-Id: I5f303c06f1e10910eb00dcfda38c6811977a91cf
2017-10-09 12:50:33 +02:00
Alex Deymo fb3b632fde Add unittest for the PatchWriter.
Split the unittest logic between bsdiff() function and the PatchWriter.
This patch now tests individually the PatchWriter logic that writes to
disk and the bsdiff() logic to create patches in the same very simple
cases.

We also update the Android.bp file to only pass -DBSDIFF_TARGET_UNITTEST
when building for the target.

Bug: 34220646
Test: ran unittests.

Change-Id: I9350157ee4a0b5a617f44bb187bd7652f6d6f017
2017-09-28 19:36:57 +02:00
Alex Deymo dcd423bf89 Add the "bsdiff/" prefix to all include paths.
This prevents accidentally including a header file from another project
that happens to have the same name.

Test: `make checkbuild`; emerge-${BOARD} bsdiff
Bug: None

Change-Id: I8af132ed388738c30a8e3d7434de70b1e9d2f924
2017-09-25 10:56:24 +02:00
Alex Deymo a28e01937d Refactor bsdiff patch writing code to another file.
bsdiff.cc had code to handle both the sub-streams compression and the
patch format. This CL moves the patch file format logic to a new class
in a separated file, and the bzip2 compression to another class. This
allows to replace the core bsdiff logic separatedly from the patch
format.

There are no changes to the functionality of bsdiff and the generated
patches. The code does a bit more of memcpy() since it doesn't write
the control stream to disk as it goes.

Bug: 34220646
Test: Ran bsdiff and compared results with previous version.

Change-Id: Ibdc1482e98cbd370cbed677c326008e19a217ef8
2017-09-15 15:33:11 +02:00
Alex Deymo 831dc45a85 Convert bsdiff to soong
Converted the Android.mk build file to soong.

Bug: None
Test: `make checkbuild`
Change-Id: Ibbc554266f7a56a5876c47b512c2a96dbade16c1
2017-09-12 11:25:06 +02:00