Skip to content

Commit

Permalink
Fix bug #54682 - UnhandledDataStructure should sanity check before al…
Browse files Browse the repository at this point in the history
…locating, not after

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1487555 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Gagravarr committed May 29, 2013
1 parent d9cd6b2 commit 25bc679
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -17,23 +17,36 @@ Licensed to the Apache Software Foundation (ASF) under one or more

package org.apache.poi.hwpf.model;

import java.util.Arrays;

import org.apache.poi.util.Internal;

/**
* A data structure used to hold some data we don't
* understand / can't handle, so we have it available
* for when we come to write back out again
*/
@Internal
public final class UnhandledDataStructure
{
byte[] _buf;

public UnhandledDataStructure(byte[] buf, int offset, int length)
{
// System.out.println("Yes, using my code");
_buf = new byte[length];
// Sanity check the size they've asked for
if (offset + length > buf.length)
{
throw new IndexOutOfBoundsException("buffer length is " + buf.length +
"but code is trying to read " + length + " from offset " + offset);
throw new IndexOutOfBoundsException("Buffer Length is " + buf.length + " " +
"but code is tried to read " + length + " from offset " + offset);
}
if (offset < 0 || length < 0)
{
throw new IndexOutOfBoundsException("Offset and Length must both be >= 0, negative " +
"indicies are not permitted - code is tried to read " + length + " from offset " + offset);
}
System.arraycopy(buf, offset, _buf, 0, length);

// Save that requested portion of the data
_buf = Arrays.copyOfRange(buf, offset, offset + length);
}

byte[] getBuf()
Expand Down

0 comments on commit 25bc679

Please sign in to comment.