Skip to content

Commit

Permalink
PageCursor.setOffset now bounds checks
Browse files Browse the repository at this point in the history
This is to uphold the assumptions of the nextBoundedPointer method, which expects the offset field to at least never underflow.
  • Loading branch information
chrisvest committed May 26, 2017
1 parent a0abeff commit f8699ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -750,6 +750,11 @@ public int copyTo( int sourceOffset, PageCursor targetCursor, int targetOffset,
public void setOffset( int offset ) public void setOffset( int offset )
{ {
this.offset = offset; this.offset = offset;
if ( offset < 0 | offset > filePageSize )
{
this.offset = 0;
outOfBounds = true;
}
} }


@Override @Override
Expand Down
Expand Up @@ -3205,7 +3205,7 @@ public void nextWithPageIdMustNotClearBoundsFlagOnWriteCursor() throws Exception
} }


@Test( timeout = SHORT_TIMEOUT_MILLIS ) @Test( timeout = SHORT_TIMEOUT_MILLIS )
public void settingOutOfBoundsCursorOffsetMustNotRaiseBoundsFlag() throws IOException public void settingOutOfBoundsCursorOffsetMustRaiseBoundsFlag() throws IOException
{ {
generateFileWithRecords( file( "a" ), 1, recordSize ); generateFileWithRecords( file( "a" ), 1, recordSize );


Expand All @@ -3214,12 +3214,15 @@ public void settingOutOfBoundsCursorOffsetMustNotRaiseBoundsFlag() throws IOExce
PageCursor cursor = pagedFile.io( 0, PF_SHARED_READ_LOCK ) ) PageCursor cursor = pagedFile.io( 0, PF_SHARED_READ_LOCK ) )
{ {
cursor.setOffset( -1 ); cursor.setOffset( -1 );
assertTrue( cursor.checkAndClearBoundsFlag() );
assertFalse( cursor.checkAndClearBoundsFlag() ); assertFalse( cursor.checkAndClearBoundsFlag() );


cursor.setOffset( filePageSize + 1 ); cursor.setOffset( filePageSize + 1 );
assertTrue( cursor.checkAndClearBoundsFlag() );
assertFalse( cursor.checkAndClearBoundsFlag() ); assertFalse( cursor.checkAndClearBoundsFlag() );


cursor.setOffset( pageCachePageSize + 1 ); cursor.setOffset( pageCachePageSize + 1 );
assertTrue( cursor.checkAndClearBoundsFlag() );
assertFalse( cursor.checkAndClearBoundsFlag() ); assertFalse( cursor.checkAndClearBoundsFlag() );
} }
} }
Expand Down

0 comments on commit f8699ff

Please sign in to comment.