Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aa2b287

Browse files
authored
Reland #7777 with proper LICENSE (#7888)
1 parent a5773d1 commit aa2b287

File tree

8 files changed

+231
-27
lines changed

8 files changed

+231
-27
lines changed

ci/licenses.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fi
4242

4343
echo "Checking license count in licenses_flutter..."
4444
actualLicenseCount=`tail -n 1 flutter/ci/licenses_golden/licenses_flutter | tr -dc '0-9'`
45-
expectedLicenseCount=2 # When changing this number: Update the error message below as well describing all expected license types.
45+
expectedLicenseCount=3 # When changing this number: Update the error message below as well describing all expected license types.
4646

4747
if [ "$actualLicenseCount" -ne "$expectedLicenseCount" ]
4848
then
@@ -53,6 +53,8 @@ then
5353
echo "double-check that all newly added files have a BSD-style license"
5454
echo "header with the following copyright:"
5555
echo " Copyright 2013 The Flutter Authors. All rights reserved."
56+
echo "Files in 'third_party/bsdiff' may have the following copyright instead:"
57+
echo " Copyright 2003-2005 Colin Percival. All rights reserved."
5658
echo "Files in 'third_party/txt' may have an Apache license header instead."
5759
echo "If you're absolutely sure that the change in license count is"
5860
echo "intentional, update 'flutter/ci/licenses.sh' with the new count."

ci/licenses_golden/licenses_flutter

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ UNUSED LICENSES:
44
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
USED LICENSES:
66

7+
====================================================================================================
8+
LIBRARY: bsdiff
9+
ORIGIN: ../../../flutter/third_party/bsdiff/LICENSE
10+
TYPE: LicenseType.bsd
11+
FILE: ../../../flutter/third_party/bsdiff/io/flutter/util/BSDiff.java
12+
----------------------------------------------------------------------------------------------------
13+
Copyright 2003-2005 Colin Percival. All rights reserved.
14+
15+
Redistribution and use in source and binary forms, with or without
16+
modification, are permitted provided that the following conditions
17+
are met:
18+
19+
1. Redistributions of source code must retain the above copyright
20+
notice, this list of conditions and the following disclaimer.
21+
2. Redistributions in binary form must reproduce the above copyright
22+
notice, this list of conditions and the following disclaimer in the
23+
documentation and/or other materials provided with the distribution.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
29+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
POSSIBILITY OF SUCH DAMAGE.
36+
====================================================================================================
37+
738
====================================================================================================
839
LIBRARY: engine
940
LIBRARY: txt
@@ -981,4 +1012,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9811012
See the License for the specific language governing permissions and
9821013
limitations under the License.
9831014
====================================================================================================
984-
Total license count: 2
1015+
Total license count: 3

shell/platform/android/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ java_library("flutter_shell_java") {
168168
"io/flutter/view/VsyncWaiter.java",
169169
]
170170

171+
java_files += [
172+
"$flutter_root/third_party/bsdiff/io/flutter/util/BSDiff.java",
173+
]
174+
171175
deps = [
172176
":android_support_v13",
173177
":android_support_annotations",

shell/platform/android/io/flutter/view/ResourceExtractor.java

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.os.AsyncTask;
1212
import android.os.Build;
1313
import android.util.Log;
14+
import io.flutter.util.BSDiff;
1415
import io.flutter.util.PathUtils;
1516
import org.json.JSONObject;
1617

@@ -19,6 +20,7 @@
1920
import java.util.HashSet;
2021
import java.util.concurrent.CancellationException;
2122
import java.util.concurrent.ExecutionException;
23+
import java.util.zip.GZIPInputStream;
2224
import java.util.zip.ZipEntry;
2325
import java.util.zip.ZipFile;
2426

@@ -29,8 +31,6 @@ class ResourceExtractor {
2931
private static final String TAG = "ResourceExtractor";
3032
private static final String TIMESTAMP_PREFIX = "res_timestamp-";
3133

32-
private static final int BUFFER_SIZE = 16 * 1024;
33-
3434
@SuppressWarnings("deprecation")
3535
static long getVersionCode(PackageInfo packageInfo) {
3636
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -177,7 +177,6 @@ private void deleteFiles() {
177177
private boolean extractAPK(File dataDir) {
178178
final AssetManager manager = mContext.getResources().getAssets();
179179

180-
byte[] buffer = null;
181180
for (String asset : mResources) {
182181
try {
183182
final File output = new File(dataDir, asset);
@@ -190,19 +189,11 @@ private boolean extractAPK(File dataDir) {
190189

191190
try (InputStream is = manager.open(asset);
192191
OutputStream os = new FileOutputStream(output)) {
193-
if (buffer == null) {
194-
buffer = new byte[BUFFER_SIZE];
195-
}
196-
197-
int count = 0;
198-
while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
199-
os.write(buffer, 0, count);
200-
}
201-
202-
os.flush();
203-
Log.i(TAG, "Extracted baseline resource " + asset);
192+
copy(is, os);
204193
}
205194

195+
Log.i(TAG, "Extracted baseline resource " + asset);
196+
206197
} catch (FileNotFoundException fnfe) {
207198
continue;
208199

@@ -219,6 +210,8 @@ private boolean extractAPK(File dataDir) {
219210
/// Returns true if successfully unpacked update resources or if there is no update,
220211
/// otherwise deletes all resources and returns false.
221212
private boolean extractUpdate(File dataDir) {
213+
final AssetManager manager = mContext.getResources().getAssets();
214+
222215
ResourceUpdater resourceUpdater = FlutterMain.getResourceUpdater();
223216
if (resourceUpdater == null) {
224217
return true;
@@ -245,11 +238,15 @@ private boolean extractUpdate(File dataDir) {
245238
return false;
246239
}
247240

248-
byte[] buffer = null;
249241
for (String asset : mResources) {
242+
boolean useDiff = false;
250243
ZipEntry entry = zipFile.getEntry(asset);
251244
if (entry == null) {
252-
continue;
245+
useDiff = true;
246+
entry = zipFile.getEntry(asset + ".bzdiff40");
247+
if (entry == null) {
248+
continue;
249+
}
253250
}
254251

255252
final File output = new File(dataDir, asset);
@@ -260,18 +257,29 @@ private boolean extractUpdate(File dataDir) {
260257
output.getParentFile().mkdirs();
261258
}
262259

263-
try (InputStream is = zipFile.getInputStream(entry);
264-
OutputStream os = new FileOutputStream(output)) {
265-
if (buffer == null) {
266-
buffer = new byte[BUFFER_SIZE];
267-
}
260+
try {
261+
if (useDiff) {
262+
ByteArrayOutputStream diff = new ByteArrayOutputStream();
263+
try (InputStream is = zipFile.getInputStream(entry)) {
264+
copy(is, diff);
265+
}
266+
267+
ByteArrayOutputStream orig = new ByteArrayOutputStream();
268+
try (InputStream is = manager.open(asset)) {
269+
copy(is, orig);
270+
}
271+
272+
try (OutputStream os = new FileOutputStream(output)) {
273+
os.write(BSDiff.bspatch(orig.toByteArray(), diff.toByteArray()));
274+
}
268275

269-
int count = 0;
270-
while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
271-
os.write(buffer, 0, count);
276+
} else {
277+
try (InputStream is = zipFile.getInputStream(entry);
278+
OutputStream os = new FileOutputStream(output)) {
279+
copy(is, os);
280+
}
272281
}
273282

274-
os.flush();
275283
Log.i(TAG, "Extracted override resource " + asset);
276284

277285
} catch (FileNotFoundException fnfe) {
@@ -339,4 +347,11 @@ private String checkTimestamp(File dataDir) {
339347

340348
return null;
341349
}
350+
351+
private static void copy(InputStream in, OutputStream out) throws IOException {
352+
byte[] buf = new byte[16 * 1024];
353+
for (int i; (i = in.read(buf)) >= 0; ) {
354+
out.write(buf, 0, i);
355+
}
356+
}
342357
}

sky/packages/sky_engine/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,6 +3492,32 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34923492
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34933493
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34943494
--------------------------------------------------------------------------------
3495+
bsdiff
3496+
3497+
Copyright 2003-2005 Colin Percival. All rights reserved.
3498+
3499+
Redistribution and use in source and binary forms, with or without
3500+
modification, are permitted provided that the following conditions
3501+
are met:
3502+
3503+
1. Redistributions of source code must retain the above copyright
3504+
notice, this list of conditions and the following disclaimer.
3505+
2. Redistributions in binary form must reproduce the above copyright
3506+
notice, this list of conditions and the following disclaimer in the
3507+
documentation and/or other materials provided with the distribution.
3508+
3509+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
3510+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3511+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3512+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
3513+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3514+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3515+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3516+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3517+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3518+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3519+
POSSIBILITY OF SUCH DAMAGE.
3520+
--------------------------------------------------------------------------------
34953521
engine
34963522
txt
34973523

third_party/bsdiff/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright 2003-2005 Colin Percival. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23+
POSSIBILITY OF SUCH DAMAGE.

third_party/bsdiff/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# BSDiff
2+
3+
Binary diff/patch algorithm based on
4+
[bsdiff 4.3](http://www.daemonology.net/bsdiff/) by Colin Percival.
5+
It's very effective at compressesing incremental changes in binaries.
6+
7+
This implementation has the following differences from Colin's code,
8+
to make it easier to read and apply patches in Java and Objective C:
9+
10+
* Using gzip instead of bzip2 because gzip is included in JDK by default
11+
* Using big- instead of little-endian serialization to simplify Java code
12+
* Using two's complement instead of high-bit coding for negatives numbers
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2003-2005 Colin Percival. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.util;
6+
7+
import java.io.*;
8+
import java.util.zip.GZIPInputStream;
9+
10+
/**
11+
* This is a Java port of algorithm from Flutter framework bsdiff.dart.
12+
* Note that this port uses 32-bit ints, which limits data size to 2GB.
13+
**/
14+
public abstract class BSDiff {
15+
public static byte[] bspatch(byte[] olddata, byte[] diffdata) throws IOException {
16+
InputStream in = new ByteArrayInputStream(diffdata, 0, diffdata.length);
17+
DataInputStream header = new DataInputStream(in);
18+
19+
byte[] magic = new byte[8];
20+
header.read(magic);
21+
if (!new String(magic).equals("BZDIFF40")) {
22+
throw new IOException("Invalid magic");
23+
}
24+
25+
int ctrllen = (int) header.readLong();
26+
int datalen = (int) header.readLong();
27+
int newsize = (int) header.readLong();
28+
header.close();
29+
30+
in = new ByteArrayInputStream(diffdata, 0, diffdata.length);
31+
in.skip(32);
32+
DataInputStream cpf = new DataInputStream(new GZIPInputStream(in));
33+
34+
in = new ByteArrayInputStream(diffdata, 0, diffdata.length);
35+
in.skip(32 + ctrllen);
36+
InputStream dpf = new GZIPInputStream(in);
37+
38+
in = new ByteArrayInputStream(diffdata, 0, diffdata.length);
39+
in.skip(32 + ctrllen + datalen);
40+
InputStream epf = new GZIPInputStream(in);
41+
42+
byte[] newdata = new byte[newsize];
43+
44+
int oldpos = 0;
45+
int newpos = 0;
46+
47+
while (newpos < newsize) {
48+
int[] ctrl = new int[3];
49+
for (int i = 0; i <= 2; i++) {
50+
ctrl[i] = (int) cpf.readLong();
51+
}
52+
if (newpos + ctrl[0] > newsize) {
53+
throw new IOException("Invalid ctrl[0]");
54+
}
55+
56+
read(dpf, newdata, newpos, ctrl[0]);
57+
58+
for (int i = 0; i < ctrl[0]; i++) {
59+
if ((oldpos + i >= 0) && (oldpos + i < olddata.length)) {
60+
newdata[newpos + i] += olddata[oldpos + i];
61+
}
62+
}
63+
64+
newpos += ctrl[0];
65+
oldpos += ctrl[0];
66+
67+
if (newpos + ctrl[1] > newsize) {
68+
throw new IOException("Invalid ctrl[0]");
69+
}
70+
71+
read(epf, newdata, newpos, ctrl[1]);
72+
73+
newpos += ctrl[1];
74+
oldpos += ctrl[2];
75+
}
76+
77+
cpf.close();
78+
dpf.close();
79+
epf.close();
80+
81+
return newdata;
82+
}
83+
84+
private static void read(InputStream in, byte[] buf, int off, int len) throws IOException {
85+
for (int i, n = 0; n < len; n += i) {
86+
if ((i = in.read(buf, off + n, len - n)) < 0) {
87+
throw new IOException("Unexpected EOF");
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)