Skip to content
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

Problem extracting zip file: illegal file name that breaks out of the target directory: / #400

Closed
Gr33nbl00d opened this issue Jan 28, 2022 · 7 comments
Assignees
Labels
bug Something isn't working resolved want feedback

Comments

@Gr33nbl00d
Copy link
Contributor

Gr33nbl00d commented Jan 28, 2022

Hi i have problem extracting a zip file which was generated by maven assembly plugin.

if (!outputFile.getCanonicalPath().startsWith(outputCanonicalPath)) {

I debuged into that place and found out that the outputfile does not have a trailing slash but the outputCannonical path variable has.
Thats what i see in the IDE

outputFile = {File@1809} "D:\Users\XXXXXXX\AppData\Local\Temp\dependentrules14443115985707206885"
outputCanonicalPath = "D:\Users\XXXXXXX\AppData\Local\Temp\dependentrules14443115985707206885\"

The zip file header looks like this:

versionMadeBy = 788
fileCommentLength = 0
diskNumberStart = 0
internalFileAttributes = {byte[2]@1817} [0, 0]
externalFileAttributes = {byte[4]@1818} [16, 0, -19, 65]
offsetLocalHeader = 5294
fileComment = null
versionNeededToExtract = 10
generalPurposeFlag = {byte[2]@1819} [0, 0]
compressionMethod = {CompressionMethod@1820} "STORE"
lastModifiedTime = 1412516727
crc = 0
compressedSize = 0
uncompressedSize = 0
fileNameLength = 1
extraFieldLength = 0
fileName = "/"
isEncrypted = false
encryptionMethod = {EncryptionMethod@1822} "NONE"
dataDescriptorExists = false
zip64ExtendedInfo = null
aesExtraDataRecord = null
fileNameUTF8Encoded = false
extraDataRecords = null
isDirectory = true
signature = {HeaderSignature@1823} "CENTRAL_DIRECTORY"

Any solution to this? Is this a bug? Anyone had the same problem?

@Gr33nbl00d
Copy link
Contributor Author

It seems like fix for #133 in commit ff3d3b3 caused that problem.
If found at least on windows new File (last line) in determineOutputFile method removes the trailing slash.

return new File(outputPath + FILE_SEPARATOR + outputFileName);

new File("d:\test\2) --> d:\test

In fix #133 you have added a file seperator to the extraction path in order somone can not extract in a different folder name. Unfortunatly the result of determineOutputFile does not contain a slash in case its the relative root folder.

String outputCanonicalPath = (new File(outputPath).getCanonicalPath()) + File.separator;

@srikanth-lingala
Copy link
Owner

@Gr33nbl00d Thanks for the PR. I merged your PR, but also made some slight adjustment to your PR. Instead of checking for just root directory, I now check if the outputFile is a directory, and append the fileSeparator if it is a directory. Can you please confirm if this change still works with your zip file?

@srikanth-lingala srikanth-lingala self-assigned this Mar 9, 2022
@srikanth-lingala
Copy link
Owner

Fixed in v2.10.0 released today

@Gr33nbl00d
Copy link
Contributor Author

I will check on wednesday if it still works. I have a day off tomorrow. Thanks for merging

@Gr33nbl00d
Copy link
Contributor Author

Hi i have verified that the bugfix fixed the problem :)

@JLLeitschuh
Copy link
Contributor

I think that #402 fixed a security vulnerability, is that indeed correct? If so, this should probably have a CVE assigned to it? Do you agree?

@JLLeitschuh
Copy link
Contributor

Friendly ping to the Snky team:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved want feedback
Projects
None yet
Development

No branches or pull requests

3 participants