-
Notifications
You must be signed in to change notification settings - Fork 272
update judge logic for v2 #513
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -252,19 +252,41 @@ private void doFullPatch(DownloadTaskParams param) throws IOException { | |||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void copyFromResource(HashMap<String, ArrayList<File> > resToCopy, HashMap<String, ArrayList<File>> resToCopy2) throws IOException { | ||||||||||||||
private void copyFromResource(HashMap<String, ArrayList<File> > resToCopy) throws IOException { | ||||||||||||||
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath())); | ||||||||||||||
Enumeration<? extends ZipEntry> entries = zipFile.entries(); | ||||||||||||||
while (entries.hasMoreElements()) { | ||||||||||||||
ZipEntry ze = entries.nextElement(); | ||||||||||||||
|
||||||||||||||
String fn = ze.getName(); | ||||||||||||||
ArrayList<File> targets = resToCopy.get(fn); | ||||||||||||||
if (targets != null) { | ||||||||||||||
File lastTarget = null; | ||||||||||||||
for (File target: targets) { | ||||||||||||||
if (UpdateContext.DEBUG) { | ||||||||||||||
Log.d("react-native-update", "Copying from resource " + fn + " to " + target); | ||||||||||||||
} | ||||||||||||||
if (lastTarget != null) { | ||||||||||||||
copyFile(lastTarget, target); | ||||||||||||||
} else { | ||||||||||||||
zipFile.unzipToFile(ze, target); | ||||||||||||||
lastTarget = target; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
zipFile.close(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void copyFromResourceV2(HashMap<String, ArrayList<File>> resToCopy2) throws IOException { | ||||||||||||||
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath())); | ||||||||||||||
Enumeration<? extends ZipEntry> entries = zipFile.entries(); | ||||||||||||||
while (entries.hasMoreElements()) { | ||||||||||||||
ZipEntry ze = entries.nextElement(); | ||||||||||||||
String fn = ze.getName(); | ||||||||||||||
long zipCrc32 = ze.getCrc(); | ||||||||||||||
String crc32Decimal = getCRC32AsDecimal(zipCrc32); | ||||||||||||||
ArrayList<File> targets = resToCopy2.get(crc32Decimal); | ||||||||||||||
if(targets==null || targets.isEmpty()){ | ||||||||||||||
targets = resToCopy.get(fn); | ||||||||||||||
} | ||||||||||||||
if (targets != null) { | ||||||||||||||
File lastTarget = null; | ||||||||||||||
for (File target: targets) { | ||||||||||||||
|
@@ -290,6 +312,7 @@ private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONEx | |||||||||||||
param.unzipDirectory.mkdirs(); | ||||||||||||||
HashMap<String, ArrayList<File>> copyList = new HashMap<String, ArrayList<File>>(); | ||||||||||||||
HashMap<String, ArrayList<File>> copiesv2List = new HashMap<String, ArrayList<File>>(); | ||||||||||||||
Boolean isV2 = false; | ||||||||||||||
|
||||||||||||||
boolean foundDiff = false; | ||||||||||||||
boolean foundBundlePatch = false; | ||||||||||||||
|
@@ -310,53 +333,56 @@ private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONEx | |||||||||||||
JSONObject copies = obj.getJSONObject("copies"); | ||||||||||||||
JSONObject copiesv2 = obj.getJSONObject("copiesv2"); | ||||||||||||||
Iterator<?> keys = copies.keys(); | ||||||||||||||
Iterator<?> keys2 = copiesv2.keys(); | ||||||||||||||
while( keys.hasNext() ) { | ||||||||||||||
String to = (String)keys.next(); | ||||||||||||||
String from = copies.getString(to); | ||||||||||||||
if (from.isEmpty()) { | ||||||||||||||
from = to; | ||||||||||||||
Iterator<?> keysV2 = copiesv2.keys(); | ||||||||||||||
if(keysV2.hasNext()){ | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Missing space after
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
isV2 = true; | ||||||||||||||
while( keysV2.hasNext() ) { | ||||||||||||||
String from = (String)keysV2.next(); | ||||||||||||||
String to = copiesv2.getString(from); | ||||||||||||||
if (from.isEmpty()) { | ||||||||||||||
from = to; | ||||||||||||||
} | ||||||||||||||
ArrayList<File> target = null; | ||||||||||||||
if (!copiesv2List.containsKey(from)) { | ||||||||||||||
target = new ArrayList<File>(); | ||||||||||||||
copiesv2List.put(from, target); | ||||||||||||||
} else { | ||||||||||||||
target = copiesv2List.get((from)); | ||||||||||||||
} | ||||||||||||||
File toFile = new File(param.unzipDirectory, to); | ||||||||||||||
|
||||||||||||||
// Fixing a Zip Path Traversal Vulnerability | ||||||||||||||
// https://support.google.com/faqs/answer/9294009 | ||||||||||||||
String canonicalPath = toFile.getCanonicalPath(); | ||||||||||||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) { | ||||||||||||||
throw new SecurityException("Illegal name: " + to); | ||||||||||||||
} | ||||||||||||||
target.add(toFile); | ||||||||||||||
} | ||||||||||||||
ArrayList<File> target = null; | ||||||||||||||
if (!copyList.containsKey(from)) { | ||||||||||||||
target = new ArrayList<File>(); | ||||||||||||||
copyList.put(from, target); | ||||||||||||||
} else { | ||||||||||||||
target = copyList.get((from)); | ||||||||||||||
} | ||||||||||||||
File toFile = new File(param.unzipDirectory, to); | ||||||||||||||
|
||||||||||||||
// Fixing a Zip Path Traversal Vulnerability | ||||||||||||||
// https://support.google.com/faqs/answer/9294009 | ||||||||||||||
String canonicalPath = toFile.getCanonicalPath(); | ||||||||||||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) { | ||||||||||||||
throw new SecurityException("Illegal name: " + to); | ||||||||||||||
}else{ | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Missing space before opening brace. Consider using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
while( keys.hasNext() ) { | ||||||||||||||
String to = (String)keys.next(); | ||||||||||||||
String from = copies.getString(to); | ||||||||||||||
if (from.isEmpty()) { | ||||||||||||||
from = to; | ||||||||||||||
} | ||||||||||||||
ArrayList<File> target = null; | ||||||||||||||
if (!copyList.containsKey(from)) { | ||||||||||||||
target = new ArrayList<File>(); | ||||||||||||||
copyList.put(from, target); | ||||||||||||||
} else { | ||||||||||||||
target = copyList.get((from)); | ||||||||||||||
} | ||||||||||||||
File toFile = new File(param.unzipDirectory, to); | ||||||||||||||
|
||||||||||||||
// Fixing a Zip Path Traversal Vulnerability | ||||||||||||||
// https://support.google.com/faqs/answer/9294009 | ||||||||||||||
String canonicalPath = toFile.getCanonicalPath(); | ||||||||||||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) { | ||||||||||||||
throw new SecurityException("Illegal name: " + to); | ||||||||||||||
} | ||||||||||||||
target.add(toFile); | ||||||||||||||
} | ||||||||||||||
target.add(toFile); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
while( keys2.hasNext() ) { | ||||||||||||||
String from = (String)keys2.next(); | ||||||||||||||
String to = copiesv2.getString(from); | ||||||||||||||
if (from.isEmpty()) { | ||||||||||||||
from = to; | ||||||||||||||
} | ||||||||||||||
ArrayList<File> target = null; | ||||||||||||||
if (!copiesv2List.containsKey(from)) { | ||||||||||||||
target = new ArrayList<File>(); | ||||||||||||||
copiesv2List.put(from, target); | ||||||||||||||
} else { | ||||||||||||||
target = copiesv2List.get((from)); | ||||||||||||||
} | ||||||||||||||
File toFile = new File(param.unzipDirectory, to); | ||||||||||||||
|
||||||||||||||
// Fixing a Zip Path Traversal Vulnerability | ||||||||||||||
// https://support.google.com/faqs/answer/9294009 | ||||||||||||||
String canonicalPath = toFile.getCanonicalPath(); | ||||||||||||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) { | ||||||||||||||
throw new SecurityException("Illegal name: " + to); | ||||||||||||||
} | ||||||||||||||
target.add(toFile); | ||||||||||||||
} | ||||||||||||||
continue; | ||||||||||||||
} | ||||||||||||||
|
@@ -385,7 +411,11 @@ private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONEx | |||||||||||||
throw new Error("bundle patch not found"); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
copyFromResource(copyList, copiesv2List); | ||||||||||||||
if(isV2){ | ||||||||||||||
copyFromResourceV2(copiesv2List); | ||||||||||||||
}else{ | ||||||||||||||
Comment on lines
+414
to
+416
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Missing spaces around
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
copyFromResource(copyList); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (UpdateContext.DEBUG) { | ||||||||||||||
Log.d("react-native-update", "Unzip finished"); | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use primitive
boolean
instead of wrapperBoolean
for simple flag variables. This avoids unnecessary object allocation and potential null pointer issues.Copilot uses AI. Check for mistakes.