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

Scan error: 'Index -1 out of bounds for length 0 #153

Closed
AlexMilotin opened this issue Dec 19, 2021 · 13 comments
Closed

Scan error: 'Index -1 out of bounds for length 0 #153

AlexMilotin opened this issue Dec 19, 2021 · 13 comments
Assignees
Labels
enhancement New feature or request patch released

Comments

@AlexMilotin
Copy link

AlexMilotin commented Dec 19, 2021

Hi,

Seems like zip file scanning is running into a error
Scan error: 'Index -1 out of bounds for length 0' on file: C:\Users\uie13286.VT1\Downloads\OneDrive_1_11-15-2021.zip

image

and
Scan error: 'malformed input off : 98, length : 1' on file: C:\Users\uix08287\Desktop\IE-DFSS-15-0003 (2).zip
Scan error: 'malformed input off : 82, length : 1' on file: C:\Users\uix08287\Desktop\IE-DFSS-15-0003.zip

image

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin Would you run with --debug and comment stacktrace for Scan error: 'Index -1 out of bounds for length 0' on file: C:\Users\uie13286.VT1\Downloads\OneDrive_1_11-15-2021.zip ?

@AlexMilotin
Copy link
Author

AlexMilotin commented Dec 19, 2021

Scan error: 'Index -1 out of bounds for length 0

Logpresso CVE-2021-44228 Vulnerability Scanner 2.3.2 (2021-12-19)
Scanning directory: C:\Users\uie13286.VT1\Downloads\OneDrive_1_11-15-2021.zip
Scan error: 'Index -1 out of bounds for length 0' on file: C:\Users\uie13286.VT1\Downloads\OneDrive_1_11-15-2021.zip
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
        at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
        at java.util.Objects.checkIndex(Objects.java:372)
        at java.util.ArrayList.get(ArrayList.java:459)
        at com.logpresso.scanner.Detector.scanStream(Detector.java:250)
        at com.logpresso.scanner.Detector.scanJarFile(Detector.java:112)
        at com.logpresso.scanner.Log4j2Scanner.traverse(Log4j2Scanner.java:306)
        at com.logpresso.scanner.Log4j2Scanner.run(Log4j2Scanner.java:146)
        at com.logpresso.scanner.Log4j2Scanner.run(Log4j2Scanner.java:69)
        at com.logpresso.scanner.Log4j2Scanner.main(Log4j2Scanner.java:30)

@AlexMilotin
Copy link
Author

AlexMilotin commented Dec 19, 2021

Also for one of the malformed perhaps would be helpful

PS C:\temp> .\log4j2-scan.exe --debug --scan-log4j1 --scan-logback --scan-zip --silent "C:\Program Files\Python36\Lib\test\zip_cp437_header.zip"
Logpresso CVE-2021-44228 Vulnerability Scanner 2.3.2 (2021-12-19)
Scanning directory: C:\Program Files\Python36\Lib\test\zip_cp437_header.zip
Scan error: 'malformed input off : 14, length : 1' on file: C:\Program Files\Python36\Lib\test\zip_cp437_header.zip
java.lang.IllegalArgumentException: malformed input off : 14, length : 1
        at java.lang.StringCoding.throwMalformed(StringCoding.java:685)
        at java.lang.StringCoding.decodeUTF8_0(StringCoding.java:872)
        at java.lang.StringCoding.newStringUTF8NoRepl(StringCoding.java:965)
        at java.lang.System$2.newStringUTF8NoRepl(System.java:2203)
        at java.util.zip.ZipCoder$UTF8.toString(ZipCoder.java:60)
        at java.util.zip.ZipCoder.toString(ZipCoder.java:87)
        at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:303)
        at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:125)
        at com.logpresso.scanner.Detector.scanStream(Detector.java:171)
        at com.logpresso.scanner.Detector.scanJarFile(Detector.java:112)
        at com.logpresso.scanner.Log4j2Scanner.traverse(Log4j2Scanner.java:306)
        at com.logpresso.scanner.Log4j2Scanner.run(Log4j2Scanner.java:146)
        at com.logpresso.scanner.Log4j2Scanner.run(Log4j2Scanner.java:69)
        at com.logpresso.scanner.Log4j2Scanner.main(Log4j2Scanner.java:30)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
        ... 14 more

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin Both exception traces are caused by encoding issues. The default zip entry encoding is utf8, but the file appears to be encoded in a different character set. Maybe adding another encoding option can be useful, however, if each zip file uses different encoding, it is hard to resolve..

@xeraph xeraph self-assigned this Dec 19, 2021
@xeraph xeraph added the discussion question or suggestion label Dec 19, 2021
@AlexMilotin
Copy link
Author

AlexMilotin commented Dec 19, 2021

@xeraph Assuming the most used ones are utf8 , latin1 and CP437 i would hope that adding latin1 and CP437 is enough ?

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin Would you upload some small CP437 zip file which causes error? I want to reproduce it.

@AlexMilotin
Copy link
Author

AlexMilotin commented Dec 19, 2021

Hopefully this is the one you need. Is what i got from one of our devs
zip_cp437_header.zip
It is the same one from the malformed error here : #153 (comment)

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin Would you test v2.3.3 release? If your system default encoding is cp437, no additional option is required. If you want to decompress ZIP which is encoded by other charset, use --zip-charset option. e.g. --zip-charset CP437

@xeraph xeraph added patch released enhancement New feature or request and removed discussion question or suggestion labels Dec 19, 2021
@AlexMilotin
Copy link
Author

That works like a charm for the malformed issues
For the Scan error: 'Index -1 out of bounds for length 0' i do not get the error anymore but instead it does Skipping it as broken .jar

image

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

Oops.. 'Index -1 out of bounds for length 0' was different issue. I will fix it soon. Thank you for reporting! @AlexMilotin

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin Would you upload zip which cause only DEFLATED entries can have EXT descriptor ?
Found some sample from https://github.com/Aefyr/SAI/files/4343980/Netflix_v7.48.0.build.10.34747.zip

@xeraph
Copy link
Contributor

xeraph commented Dec 19, 2021

@AlexMilotin v2.3.4 reduces only DEFLATED entries can have EXT descriptor errors.
(still error occurs for nested zip case due to jdk limitation)

@xeraph
Copy link
Contributor

xeraph commented Dec 22, 2021

@AlexMilotin v2.6.0 release can resolves almost all ZIP errors.

@xeraph xeraph closed this as completed Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request patch released
Projects
None yet
Development

No branches or pull requests

2 participants