Skip to content

Commit

Permalink
Check page bounds on accesses in MetaDataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Apr 7, 2016
1 parent f5aefc6 commit 9c38a5a
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 33 deletions.
@@ -0,0 +1,203 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache;

import java.io.File;
import java.io.IOException;

public class DelegatingPageCursor implements PageCursor
{
private final PageCursor delegate;

public byte getByte()
{
return delegate.getByte();
}

public int copyTo( int sourceOffset, PageCursor targetCursor, int targetOffset, int lengthInBytes )
{
return delegate.copyTo( sourceOffset, targetCursor, targetOffset, lengthInBytes );
}

public void putInt( int value )
{
delegate.putInt( value );
}

public void getBytes( byte[] data )
{
delegate.getBytes( data );
}

public boolean next() throws IOException
{
return delegate.next();
}

public void putBytes( byte[] data )
{
delegate.putBytes( data );
}

public short getShort()
{
return delegate.getShort();
}

public File getCurrentFile()
{
return delegate.getCurrentFile();
}

public void putShort( short value )
{
delegate.putShort( value );
}

public long getUnsignedInt()
{
return delegate.getUnsignedInt();
}

public short getShort( int offset )
{
return delegate.getShort( offset );
}

public int getCurrentPageSize()
{
return delegate.getCurrentPageSize();
}

public long getLong()
{
return delegate.getLong();
}

public void putLong( long value )
{
delegate.putLong( value );
}

public int getOffset()
{
return delegate.getOffset();
}

public void close()
{
delegate.close();
}

public void putByte( int offset, byte value )
{
delegate.putByte( offset, value );
}

public void putInt( int offset, int value )
{
delegate.putInt( offset, value );
}

public void putBytes( byte[] data, int arrayOffset, int length )
{
delegate.putBytes( data, arrayOffset, length );
}

public void rewind()
{
delegate.rewind();
}

public void putByte( byte value )
{
delegate.putByte( value );
}

public long getUnsignedInt( int offset )
{
return delegate.getUnsignedInt( offset );
}

public boolean checkAndClearBoundsFlag()
{
return delegate.checkAndClearBoundsFlag();
}

public long getCurrentPageId()
{
return delegate.getCurrentPageId();
}

public void putShort( int offset, short value )
{
delegate.putShort( offset, value );
}

public boolean next( long pageId ) throws IOException
{
return delegate.next( pageId );
}

public void putLong( int offset, long value )
{
delegate.putLong( offset, value );
}

public long getLong( int offset )
{
return delegate.getLong( offset );
}

public void getBytes( byte[] data, int arrayOffset, int length )
{
delegate.getBytes( data, arrayOffset, length );
}

public int getInt( int offset )
{
return delegate.getInt( offset );
}

public void setOffset( int offset )
{
delegate.setOffset( offset );
}

public byte getByte( int offset )
{
return delegate.getByte( offset );
}

public int getInt()
{
return delegate.getInt();
}

public boolean shouldRetry() throws IOException
{
return delegate.shouldRetry();
}

public DelegatingPageCursor( PageCursor delegate )
{
this.delegate = delegate;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache;

import java.io.IOException;

public class DelegatingPagedFile implements PagedFile
{
private final PagedFile delegate;

public DelegatingPagedFile( PagedFile delegate )
{
this.delegate = delegate;
}

public PageCursor io( long pageId, int pf_flags ) throws IOException
{
return delegate.io( pageId, pf_flags );
}

public void flushAndForce() throws IOException
{
delegate.flushAndForce();
}

public long getLastPageId() throws IOException
{
return delegate.getLastPageId();
}

public int pageSize()
{
return delegate.pageSize();
}

public void close() throws IOException
{
delegate.close();
}

public void flushAndForce( IOLimiter limiter ) throws IOException
{
delegate.flushAndForce( limiter );
}
}
Expand Up @@ -236,11 +236,17 @@ private void throwOutOfBoundsException( long recordId )
record.setId( recordId ); record.setId( recordId );
long pageId = pageIdForRecord( recordId ); long pageId = pageIdForRecord( recordId );
int offset = offsetForId( recordId ); int offset = offsetForId( recordId );
throw new UnderlyingStorageException( throw new UnderlyingStorageException( buildOutOfBoundsExceptionMessage(
"Access to record " + record + " went out of bounds of the page. The record size is " + record, pageId, offset, recordSize, storeFile.pageSize(), storageFileName.getAbsolutePath() ) );
recordSize + " bytes, and the access was at offset " + offset + " bytes into page " + }
pageId + ", and the pages have a capacity of " + storeFile.pageSize() + " bytes. " +
"The mapped store file in question is " + storageFileName.getAbsolutePath() ); protected static String buildOutOfBoundsExceptionMessage( AbstractBaseRecord record, long pageId, int offset,
int recordSize, int pageSize, String filename )
{
return "Access to record " + record + " went out of bounds of the page. The record size is " +
recordSize + " bytes, and the access was at offset " + offset + " bytes into page " +
pageId + ", and the pages have a capacity of " + pageSize + " bytes. " +
"The mapped store file in question is " + filename;
} }


protected void createHeaderRecord( PageCursor cursor ) throws IOException protected void createHeaderRecord( PageCursor cursor ) throws IOException
Expand Down

0 comments on commit 9c38a5a

Please sign in to comment.