DATACMNS-1327 - Prevent int overflow in AbstractPageRequest#getOffset().

Original pull request: #291.
This commit is contained in:
Alex Bondarev
2018-05-21 17:15:10 +03:00
committed by Jens Schauder
parent fffce66bdd
commit d6f39afe00
2 changed files with 11 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
*
* @author Thomas Darimont
* @author Oliver Gierke
* @author Alex Bondarev
*/
public abstract class AbstractPageRequest implements Pageable, Serializable {
@@ -74,7 +75,7 @@ public abstract class AbstractPageRequest implements Pageable, Serializable {
* @see org.springframework.data.domain.Pageable#getOffset()
*/
public long getOffset() {
return page * size;
return (long) page * (long) size;
}
/*

View File

@@ -22,6 +22,7 @@ import org.junit.Test;
/**
* @author Thomas Darimont
* @author Alex Bondarev
*/
public abstract class AbstractPageRequestUnitTests {
@@ -75,4 +76,12 @@ public abstract class AbstractPageRequestUnitTests {
public void preventsPageSizeLessThanOne() {
newPageRequest(0, 0);
}
@Test
public void getOffsetShouldNotCauseOverflow() {
AbstractPageRequest request = newPageRequest(Integer.MAX_VALUE, Integer.MAX_VALUE);
assertThat(request.getOffset()).isGreaterThan(Integer.MAX_VALUE);
}
}