提交 bc81fa52 编写于 作者: R Rossen Stoyanchev

Reject range starting above resource length

Closes: gh-23576
上级 70bbe712
......@@ -65,6 +65,7 @@ public abstract class HttpRange {
long contentLength = getLengthFor(resource);
long start = getRangeStart(contentLength);
long end = getRangeEnd(contentLength);
Assert.isTrue(start < contentLength, "'position' exceeds the resource length " + contentLength);
return new ResourceRegion(resource, start, end - start + 1);
}
......
......@@ -158,8 +158,7 @@ public class HttpRangeTests {
ByteArrayResource resource = mock(ByteArrayResource.class);
given(resource.contentLength()).willReturn(-1L);
HttpRange range = HttpRange.createByteRange(0, 9);
assertThatIllegalArgumentException().isThrownBy(() ->
range.toResourceRegion(resource));
assertThatIllegalArgumentException().isThrownBy(() -> range.toResourceRegion(resource));
}
@Test
......@@ -167,8 +166,15 @@ public class HttpRangeTests {
InputStreamResource resource = mock(InputStreamResource.class);
given(resource.contentLength()).willThrow(IOException.class);
HttpRange range = HttpRange.createByteRange(0, 9);
assertThatIllegalArgumentException().isThrownBy(() ->
range.toResourceRegion(resource));
assertThatIllegalArgumentException().isThrownBy(() -> 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册