Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
ADFA-5005: Fix SDK bootstrap crash extracting android-sdk.zip#1621
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
250db8360f124acf98828c287d5bff234efdbc21bbca81ae99640564a3046a3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -245,6 +245,14 @@ object AssetsInstallationHelper { | ||
| Files.createDirectories(destDir) | ||
| // Normalize and make destDir absolute for secure path validation | ||
| val normalizedDestDir = destDir.toAbsolutePath().normalize() | ||
| val realDestDir = normalizedDestDir.toRealPath() | ||
| // Zip entries are commonly clustered by directory (e.g. dozens of files | ||
| // under the same build-tools/<version>/ prefix); cache the last-verified | ||
| // parent so consecutive entries under it skip a redundant toRealPath() call. | ||
| // Nothing below can turn an already-verified real directory into a symlink | ||
| // mid-run, so caching by lexical parent equality is safe. | ||
| var lastVerifiedParent: Path? = null | ||
| ZipInputStream(srcStream.buffered()).useEntriesEach { zipInput, entry -> | ||
| // Validate entry name doesn't contain dangerous patterns | ||
| @@ -260,9 +268,28 @@ object AssetsInstallationHelper { | ||
| throw IllegalStateException("Entry is outside of the target dir: ${entry.name}") | ||
| } | ||
| // The checks above are lexical (entry name only) and don't catch a symlink | ||
| // already present on disk (e.g. destDir merged/reused across installer | ||
| // runs). Reject writing through an existing symlink up front, then | ||
| // re-check containment against the real, on-disk path once created. | ||
| if (Files.isSymbolicLink(destFile)) { | ||
| throw IllegalStateException("Refusing to extract over an existing symlink: ${entry.name}") | ||
| } | ||
| if (entry.isDirectory) { | ||
| Files.createDirectories(destFile) | ||
| if (!destFile.toRealPath().startsWith(realDestDir)) { | ||
| throw IllegalStateException("Entry escapes the target dir via symlink: ${entry.name}") | ||
| } | ||
| } else { | ||
| Files.createDirectories(destFile.parent) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (destFile.parent != lastVerifiedParent) { | ||
| if (!destFile.parent.toRealPath().startsWith(realDestDir)) { | ||
hal-eisen-adfa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| throw IllegalStateException("Entry parent escapes the target dir via symlink: ${entry.name}") | ||
| } | ||
| lastVerifiedParent = destFile.parent | ||
| } | ||
| Files.newOutputStream(destFile).use { dest -> | ||
| zipInput.copyTo(dest) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.