-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Multi-byte filenames in zip files can cause an endless loop in ZipString.hash #38751
Comments
Thanks for the report.
Any jar that reproduces the problem would be useful so that we can reproduce the problem, or even just a concrete example of the file names that cause the problem. |
The ZIP record for the file as produced by zipdump is this: 000c8687: PK.0304: 0014 0800 0008 5788834c 04267862 00000fad 00002e4f 0054 0000 | 000c86a5 000c86f9 000c86f9 000c96a6 - de/genopace/bsh/pe/darlehen/validierung/FehlendeOderUngültigeBaufiSmartKosten.class The path has the length 0x54 == 84. The data block happens to contain only 56 bytes of that path, which is the first half of the character |
I wonder if we've already fixed this with #38572. @jhackel-hypo Any chance you could try 3.2.1-SNAPSHOT before we try anything else? |
I have no way to deliberately build a broken JAR. It just happens from time to time. On the main branch, this test will also hang @Test
void hashDataBlockWithInCompleteMultiByteCharacterAtTheEnd() throws IOException {
ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(
(byte) 100, (byte) 101, (byte) 47, (byte) 103, (byte) 101, (byte) 110,
(byte) 111, (byte) 112, (byte) 97, (byte) 99, (byte) 101, (byte) 47,
(byte) 98, (byte) 115, (byte) 104, (byte) 47, (byte) 112, (byte) 101,
(byte) 47, (byte) 100, (byte) 97, (byte) 114, (byte) 108, (byte) 101,
(byte) 104, (byte) 101, (byte) 110, (byte) 47, (byte) 118, (byte) 97,
(byte) 108, (byte) 105, (byte) 100, (byte) 105, (byte) 101, (byte) 114,
(byte) 117, (byte) 110, (byte) 103, (byte) 47, (byte) 70, (byte) 101,
(byte) 104, (byte) 108, (byte) 101, (byte) 110, (byte) 100, (byte) 101,
(byte) 79, (byte) 100, (byte) 101, (byte) 114, (byte) 85, (byte) 110,
(byte) 103, (byte) -61
);
ZipString.hash(null, dataBlock, 0, 87, true);
} This pretty much the same which I do not really grasp how |
It seems to me that |
I think, I do understand the problem now. I am also pretty sure that 8c7e877 is not fixing the problem. The problem is, that Lines 111 to 121 in a242bd8
But this is not the case. The data block has half of the multibyte character at the last position of its Lines 179 to 183 in c50172d
But because |
The implementation of |
I guess a possible solution could be to use Lines 276 to 286 in a242bd8
The returned The method |
Thanks very much for the detailed analysis @jhackel-hypo! I think I've pushed something that will fix this. I'm not keen to move |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.apache.maven.plugins:maven-surefire-plugin](https://maven.apache.org/surefire/) | build | patch | `3.2.2` -> `3.2.5` | | [org.apache.maven.plugins:maven-failsafe-plugin](https://maven.apache.org/surefire/) | build | patch | `3.2.2` -> `3.2.5` | | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.2.0` -> `3.2.1` | --- ### Release Notes <details> <summary>spring-projects/spring-boot (org.springframework.boot:spring-boot-starter-parent)</summary> ### [`v3.2.1`](https://github.com/spring-projects/spring-boot/releases/tag/v3.2.1) [Compare Source](spring-projects/spring-boot@v3.2.0...v3.2.1) #### 🐞 Bug Fixes - HibernateJpaAutoConfiguration should be applied before DataSourceTransactionManagerAutoConfiguration [#​38880](spring-projects/spring-boot#38880) - META-INF entries are duplicated under BOOT-INF/classes causing "Conflicting persistence unit definitions" error [#​38862](spring-projects/spring-boot#38862) - logging.include-application-name has no effect when using log4j2 [#​38847](spring-projects/spring-boot#38847) - Pulsar authentication param properties cause IllegalStateException with Pulsar Client 3.1.0 [#​38839](spring-projects/spring-boot#38839) - Child context created with SpringApplicationBuilder runs parents runners [#​38837](spring-projects/spring-boot#38837) - getSigners() info is lost for signed jars when using the new loader implementation with requiresUnpack [#​38833](spring-projects/spring-boot#38833) - TestContainers parallel initialization doesn't work properly [#​38831](spring-projects/spring-boot#38831) - Zip file closed exceptions can be thrown due to StaticResourceJars closing jars from cached connections [#​38770](spring-projects/spring-boot#38770) - Multi-byte filenames in zip files can cause an endless loop in ZipString.hash [#​38751](spring-projects/spring-boot#38751) - Gradle task "bootJar" fails with "Failed to get permissions" when using Gradle 8.6-milestone-1 [#​38741](spring-projects/spring-boot#38741) - Custom binding converters are ignored when working with collection types [#​38734](spring-projects/spring-boot#38734) - WebFlux and resource server auto-configuration may fail due to null authentication manager [#​38713](spring-projects/spring-boot#38713) - It is unclear that Docker Compose services have not been started as one or more is already run...
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.apache.maven.plugins:maven-surefire-plugin](https://maven.apache.org/surefire/) | build | patch | `3.2.2` -> `3.2.5` | | [org.apache.maven.plugins:maven-failsafe-plugin](https://maven.apache.org/surefire/) | build | patch | `3.2.2` -> `3.2.5` | | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.2.0` -> `3.2.1` | --- ### Release Notes <details> <summary>spring-projects/spring-boot (org.springframework.boot:spring-boot-starter-parent)</summary> ### [`v3.2.1`](https://github.com/spring-projects/spring-boot/releases/tag/v3.2.1) [Compare Source](spring-projects/spring-boot@v3.2.0...v3.2.1) #### 🐞 Bug Fixes - HibernateJpaAutoConfiguration should be applied before DataSourceTransactionManagerAutoConfiguration [#​38880](spring-projects/spring-boot#38880) - META-INF entries are duplicated under BOOT-INF/classes causing "Conflicting persistence unit definitions" error [#​38862](spring-projects/spring-boot#38862) - logging.include-application-name has no effect when using log4j2 [#​38847](spring-projects/spring-boot#38847) - Pulsar authentication param properties cause IllegalStateException with Pulsar Client 3.1.0 [#​38839](spring-projects/spring-boot#38839) - Child context created with SpringApplicationBuilder runs parents runners [#​38837](spring-projects/spring-boot#38837) - getSigners() info is lost for signed jars when using the new loader implementation with requiresUnpack [#​38833](spring-projects/spring-boot#38833) - TestContainers parallel initialization doesn't work properly [#​38831](spring-projects/spring-boot#38831) - Zip file closed exceptions can be thrown due to StaticResourceJars closing jars from cached connections [#​38770](spring-projects/spring-boot#38770) - Multi-byte filenames in zip files can cause an endless loop in ZipString.hash [#​38751](spring-projects/spring-boot#38751) - Gradle task "bootJar" fails with "Failed to get permissions" when using Gradle 8.6-milestone-1 [#​38741](spring-projects/spring-boot#38741) - Custom binding converters are ignored when working with collection types [#​38734](spring-projects/spring-boot#38734) - WebFlux and resource server auto-configuration may fail due to null authentication manager [#​38713](spring-projects/spring-boot#38713) - It is unclear that Docker Compose services have not been started as one or more is already run...
Our Spring Boot 3.2.0 app hangs for random builds during a very early start-up phase. We see this thread-dump:
I am not sure what this code exactly does, but it seems to calculate a hash code of a a file name from a JAR file embedded in the super-jar of our app. The code seems to operate on
DataBlock
instances of the central ZIP file directory.The error occurs because the block it is processing happens to only contain the first half of the file name. Unfortunately, the last byte in the data block is the first byte of multi-byte character. It seems, this code tries to read the whole multi-byte character:
spring-boot/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/zip/ZipString.java
Lines 117 to 121 in a242bd8
But the data block seems to be unable to provide the missing byte, because it will not read any further data from the underlying file channel. It returns only the first byte of the multi-byte character again and again. And the hash function hangs.
I am not deep enough into it, do dig what is exactly going on. Furthermore, I am unable to provide the broken JAR as it comes from a closed source project.
The text was updated successfully, but these errors were encountered: