Merge branch '4.0.x'

Closes gh-50410
This commit is contained in:
Phillip Webb
2026-05-12 11:48:40 -07:00
4 changed files with 30 additions and 1 deletions
@@ -107,6 +107,7 @@ public class LogUpdateEvent extends UpdateEvent {
}
private static byte @Nullable [] read(InputStream inputStream, long size) throws IOException {
Assert.state(size <= Integer.MAX_VALUE, () -> "Log update event data is too large (%d bytes)".formatted(size));
byte[] data = new byte[(int) size];
int offset = 0;
do {
@@ -75,7 +75,10 @@ public interface Content {
*/
static Content of(File file) {
Assert.notNull(file, "'file' must not be null");
return of((int) file.length(), () -> new FileInputStream(file));
long length = file.length();
Assert.state(length <= Integer.MAX_VALUE,
() -> "'file' is too large (%d bytes) to be used as content".formatted(length));
return of((int) length, () -> new FileInputStream(file));
}
/**
@@ -16,6 +16,7 @@
package org.springframework.boot.buildpack.platform.docker;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -60,6 +61,19 @@ class LogUpdateEventTests {
assertThat(events.get(0)).hasToString("Stream type is out of bounds. Must be >= 0 and < 3, but was 3");
}
@Test
void readAllWhenPayloadSizeExceedsIntMaxReturnsErrorEvent() throws IOException {
// Docker multiplexed stream header: 1 byte stream type (1=STDOUT),
// 3 padding bytes, 4 bytes big-endian size (0xFFFFFFFF = 4294967295)
byte[] header = new byte[] { 1, 0, 0, 0, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
List<LogUpdateEvent> events = new ArrayList<>();
try (InputStream inputStream = new ByteArrayInputStream(header)) {
LogUpdateEvent.readAll(inputStream, events::add);
}
assertThat(events).hasSize(1);
assertThat(events.get(0)).hasToString("Log update event data is too large (4294967295 bytes)");
}
private List<LogUpdateEvent> readAll(String name) throws IOException {
List<LogUpdateEvent> events = new ArrayList<>();
try (InputStream inputStream = getClass().getResourceAsStream(name)) {
@@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@@ -26,6 +27,9 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link Content}.
@@ -76,6 +80,13 @@ class ContentTests {
assertThat(writeToAndGetBytes(writable)).isEqualTo(bytes);
}
@Test
void ofFileWhenFileTooLargeThrowsException() {
File file = mock(File.class);
given(file.length()).willReturn((long) Integer.MAX_VALUE + 1);
assertThatIllegalStateException().isThrownBy(() -> Content.of(file)).withMessageContaining("too large");
}
private byte[] writeToAndGetBytes(Content writable) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writable.writeTo(outputStream);