Skip to content

Commit

Permalink
Fixed issue when mapping beyond EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
PhRX committed Jan 12, 2017
1 parent 4f16eff commit 430916c
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -131,7 +131,16 @@ public void close() throws IOException
*/
private void mapBuffer(long offset) throws IOException
{
buffer = channel.map(READ_ONLY, offset, BUFFER_SIZE);
int length = BUFFER_SIZE;
long fileEnd = channel.size();

if (offset + BUFFER_SIZE > fileEnd)
{
// Cast to int is safe, since the test determines that the int
// BUFFER_SIZE > fileEnd - offset)
length = (int) (fileEnd - offset);
}
buffer = channel.map(READ_ONLY, offset, length);
}

@Override
Expand Down

0 comments on commit 430916c

Please sign in to comment.