Reject range starting above resource length
Closes: gh-23576
This commit is contained in:
parent
70bbe71235
commit
bc81fa520e
|
@ -65,6 +65,7 @@ public abstract class HttpRange {
|
||||||
long contentLength = getLengthFor(resource);
|
long contentLength = getLengthFor(resource);
|
||||||
long start = getRangeStart(contentLength);
|
long start = getRangeStart(contentLength);
|
||||||
long end = getRangeEnd(contentLength);
|
long end = getRangeEnd(contentLength);
|
||||||
|
Assert.isTrue(start < contentLength, "'position' exceeds the resource length " + contentLength);
|
||||||
return new ResourceRegion(resource, start, end - start + 1);
|
return new ResourceRegion(resource, start, end - start + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,8 +158,7 @@ public class HttpRangeTests {
|
||||||
ByteArrayResource resource = mock(ByteArrayResource.class);
|
ByteArrayResource resource = mock(ByteArrayResource.class);
|
||||||
given(resource.contentLength()).willReturn(-1L);
|
given(resource.contentLength()).willReturn(-1L);
|
||||||
HttpRange range = HttpRange.createByteRange(0, 9);
|
HttpRange range = HttpRange.createByteRange(0, 9);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() -> range.toResourceRegion(resource));
|
||||||
range.toResourceRegion(resource));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -167,8 +166,15 @@ public class HttpRangeTests {
|
||||||
InputStreamResource resource = mock(InputStreamResource.class);
|
InputStreamResource resource = mock(InputStreamResource.class);
|
||||||
given(resource.contentLength()).willThrow(IOException.class);
|
given(resource.contentLength()).willThrow(IOException.class);
|
||||||
HttpRange range = HttpRange.createByteRange(0, 9);
|
HttpRange range = HttpRange.createByteRange(0, 9);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() -> range.toResourceRegion(resource));
|
||||||
range.toResourceRegion(resource));
|
}
|
||||||
|
|
||||||
|
@Test // gh-23576
|
||||||
|
public void toResourceRegionStartingAtResourceByteCount() {
|
||||||
|
byte[] bytes = "Spring Framework".getBytes(StandardCharsets.UTF_8);
|
||||||
|
ByteArrayResource resource = new ByteArrayResource(bytes);
|
||||||
|
HttpRange range = HttpRange.createByteRange(resource.contentLength());
|
||||||
|
assertThatIllegalArgumentException().isThrownBy(() -> range.toResourceRegion(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue