HHH-12369 Fix for integer overflow in limit handler when using Integer.MAX_VALUE for maxResults on DB2

This commit is contained in:
Christian Beikov 2018-03-07 17:53:33 +01:00 committed by Andrea Boriero
parent 5aaabb0f03
commit 58af371440
2 changed files with 16 additions and 2 deletions

View File

@ -169,6 +169,13 @@ public abstract class AbstractLimitHandler implements LimitHandler {
protected final int getMaxOrLimit(RowSelection selection) { protected final int getMaxOrLimit(RowSelection selection) {
final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) );
final int lastRow = selection.getMaxRows(); final int lastRow = selection.getMaxRows();
return useMaxForLimit() ? lastRow + firstRow : lastRow; final int maxRows = useMaxForLimit() ? lastRow + firstRow : lastRow;
// Use Integer.MAX_VALUE on overflow
if ( maxRows < 0 ) {
return Integer.MAX_VALUE;
}
else {
return maxRows;
}
} }
} }

View File

@ -42,7 +42,14 @@ public class NoopLimitHandler extends AbstractLimitHandler {
@Override @Override
public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException { public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException {
if ( LimitHelper.hasMaxRows( selection ) ) { if ( LimitHelper.hasMaxRows( selection ) ) {
statement.setMaxRows( selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ) ); int maxRows = selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) );
// Use Integer.MAX_VALUE on overflow
if ( maxRows < 0 ) {
statement.setMaxRows( Integer.MAX_VALUE );
}
else {
statement.setMaxRows( maxRows );
}
} }
} }
} }