react-native-update 10.32.0 → 10.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|
|
25
25
|
import java.util.Enumeration;
|
|
26
26
|
import java.util.Iterator;
|
|
27
27
|
import java.util.zip.ZipEntry;
|
|
28
|
+
import java.util.zip.CRC32;
|
|
28
29
|
import java.util.HashMap;
|
|
29
30
|
|
|
30
31
|
import okio.BufferedSink;
|
|
@@ -100,7 +101,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
100
101
|
if (UpdateContext.DEBUG) {
|
|
101
102
|
Log.d("react-native-update", "Progress " + received + "/" + contentLength);
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
|
|
104
105
|
int percentage = (int)(received * 100.0 / contentLength + 0.5);
|
|
105
106
|
if (percentage > currentPercentage) {
|
|
106
107
|
currentPercentage = percentage;
|
|
@@ -198,6 +199,10 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
198
199
|
return fout.toByteArray();
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
private String getCRC32AsDecimal(long crc32Value) {
|
|
203
|
+
return String.valueOf(crc32Value & 0xFFFFFFFFL);
|
|
204
|
+
}
|
|
205
|
+
|
|
201
206
|
private void copyFilesWithBlacklist(String current, File from, File to, JSONObject blackList) throws IOException {
|
|
202
207
|
File[] files = from.listFiles();
|
|
203
208
|
for (File file : files) {
|
|
@@ -273,12 +278,41 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
273
278
|
zipFile.close();
|
|
274
279
|
}
|
|
275
280
|
|
|
281
|
+
private void copyFromResourceV2(HashMap<String, ArrayList<File>> resToCopy2) throws IOException {
|
|
282
|
+
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath()));
|
|
283
|
+
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
|
284
|
+
while (entries.hasMoreElements()) {
|
|
285
|
+
ZipEntry ze = entries.nextElement();
|
|
286
|
+
String fn = ze.getName();
|
|
287
|
+
long zipCrc32 = ze.getCrc();
|
|
288
|
+
String crc32Decimal = getCRC32AsDecimal(zipCrc32);
|
|
289
|
+
ArrayList<File> targets = resToCopy2.get(crc32Decimal);
|
|
290
|
+
if (targets != null) {
|
|
291
|
+
File lastTarget = null;
|
|
292
|
+
for (File target: targets) {
|
|
293
|
+
if (UpdateContext.DEBUG) {
|
|
294
|
+
Log.d("react-native-update", "Copying from resource " + fn + " to " + target);
|
|
295
|
+
}
|
|
296
|
+
if (lastTarget != null) {
|
|
297
|
+
copyFile(lastTarget, target);
|
|
298
|
+
} else {
|
|
299
|
+
zipFile.unzipToFile(ze, target);
|
|
300
|
+
lastTarget = target;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
zipFile.close();
|
|
306
|
+
}
|
|
307
|
+
|
|
276
308
|
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
|
|
277
309
|
downloadFile(param);
|
|
278
310
|
|
|
279
311
|
removeDirectory(param.unzipDirectory);
|
|
280
312
|
param.unzipDirectory.mkdirs();
|
|
281
313
|
HashMap<String, ArrayList<File>> copyList = new HashMap<String, ArrayList<File>>();
|
|
314
|
+
HashMap<String, ArrayList<File>> copiesv2List = new HashMap<String, ArrayList<File>>();
|
|
315
|
+
Boolean isV2 = false;
|
|
282
316
|
|
|
283
317
|
boolean foundDiff = false;
|
|
284
318
|
boolean foundBundlePatch = false;
|
|
@@ -297,29 +331,58 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
297
331
|
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
|
298
332
|
|
|
299
333
|
JSONObject copies = obj.getJSONObject("copies");
|
|
334
|
+
JSONObject copiesv2 = obj.getJSONObject("copiesv2");
|
|
300
335
|
Iterator<?> keys = copies.keys();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
from =
|
|
336
|
+
Iterator<?> keysV2 = copiesv2.keys();
|
|
337
|
+
if(keysV2.hasNext()){
|
|
338
|
+
isV2 = true;
|
|
339
|
+
while( keysV2.hasNext() ) {
|
|
340
|
+
String from = (String)keysV2.next();
|
|
341
|
+
String to = copiesv2.getString(from);
|
|
342
|
+
if (from.isEmpty()) {
|
|
343
|
+
from = to;
|
|
344
|
+
}
|
|
345
|
+
ArrayList<File> target = null;
|
|
346
|
+
if (!copiesv2List.containsKey(from)) {
|
|
347
|
+
target = new ArrayList<File>();
|
|
348
|
+
copiesv2List.put(from, target);
|
|
349
|
+
} else {
|
|
350
|
+
target = copiesv2List.get((from));
|
|
351
|
+
}
|
|
352
|
+
File toFile = new File(param.unzipDirectory, to);
|
|
353
|
+
|
|
354
|
+
// Fixing a Zip Path Traversal Vulnerability
|
|
355
|
+
// https://support.google.com/faqs/answer/9294009
|
|
356
|
+
String canonicalPath = toFile.getCanonicalPath();
|
|
357
|
+
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
|
358
|
+
throw new SecurityException("Illegal name: " + to);
|
|
359
|
+
}
|
|
360
|
+
target.add(toFile);
|
|
306
361
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
362
|
+
}else{
|
|
363
|
+
while( keys.hasNext() ) {
|
|
364
|
+
String to = (String)keys.next();
|
|
365
|
+
String from = copies.getString(to);
|
|
366
|
+
if (from.isEmpty()) {
|
|
367
|
+
from = to;
|
|
368
|
+
}
|
|
369
|
+
ArrayList<File> target = null;
|
|
370
|
+
if (!copyList.containsKey(from)) {
|
|
371
|
+
target = new ArrayList<File>();
|
|
372
|
+
copyList.put(from, target);
|
|
373
|
+
} else {
|
|
374
|
+
target = copyList.get((from));
|
|
375
|
+
}
|
|
376
|
+
File toFile = new File(param.unzipDirectory, to);
|
|
377
|
+
|
|
378
|
+
// Fixing a Zip Path Traversal Vulnerability
|
|
379
|
+
// https://support.google.com/faqs/answer/9294009
|
|
380
|
+
String canonicalPath = toFile.getCanonicalPath();
|
|
381
|
+
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
|
382
|
+
throw new SecurityException("Illegal name: " + to);
|
|
383
|
+
}
|
|
384
|
+
target.add(toFile);
|
|
321
385
|
}
|
|
322
|
-
target.add(toFile);
|
|
323
386
|
}
|
|
324
387
|
continue;
|
|
325
388
|
}
|
|
@@ -348,7 +411,11 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
348
411
|
throw new Error("bundle patch not found");
|
|
349
412
|
}
|
|
350
413
|
|
|
351
|
-
|
|
414
|
+
if(isV2){
|
|
415
|
+
copyFromResourceV2(copiesv2List);
|
|
416
|
+
}else{
|
|
417
|
+
copyFromResource(copyList);
|
|
418
|
+
}
|
|
352
419
|
|
|
353
420
|
if (UpdateContext.DEBUG) {
|
|
354
421
|
Log.d("react-native-update", "Unzip finished");
|