mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-09-13 21:56:19 +00:00
Merge remote-tracking branch 'origin/GP-2523_ryanmkurtz_ChainedBuffer1byte--SQUASHED' into patch
This commit is contained in:
commit
94a788c084
|
@ -1117,7 +1117,7 @@ public class ChainedBuffer implements Buffer {
|
||||||
/**
|
/**
|
||||||
* Fill the buffer over the specified range with a byte value.
|
* Fill the buffer over the specified range with a byte value.
|
||||||
* @param startOffset starting offset, inclusive
|
* @param startOffset starting offset, inclusive
|
||||||
* @param endOffset ending offset, exclusive
|
* @param endOffset ending offset, inclusive
|
||||||
* @param fillByte byte value
|
* @param fillByte byte value
|
||||||
* @throws IOException thrown if an IO error occurs
|
* @throws IOException thrown if an IO error occurs
|
||||||
*/
|
*/
|
||||||
|
@ -1126,10 +1126,10 @@ public class ChainedBuffer implements Buffer {
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
throw new UnsupportedOperationException("Read-only buffer");
|
throw new UnsupportedOperationException("Read-only buffer");
|
||||||
}
|
}
|
||||||
if (endOffset <= startOffset) {
|
if (endOffset < startOffset) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
if (startOffset < 0 || endOffset > size) {
|
if (startOffset < 0 || endOffset >= size) {
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
byte[] fillData = new byte[dataSpace];
|
byte[] fillData = new byte[dataSpace];
|
||||||
|
|
|
@ -100,7 +100,7 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFillChainnedBuffer() throws IOException {
|
public void testFillChainedBuffer() throws IOException {
|
||||||
|
|
||||||
ChainedBuffer cb =
|
ChainedBuffer cb =
|
||||||
new ChainedBuffer(BIG_DATA_SIZE, obfuscated, sourceData, sourceDataOffset, mgr);
|
new ChainedBuffer(BIG_DATA_SIZE, obfuscated, sourceData, sourceDataOffset, mgr);
|
||||||
|
@ -126,7 +126,42 @@ public abstract class AbstractChainedBufferTest extends AbstractGenericTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBigChainnedBuffer() throws IOException {
|
public void testSmallFillChainedBuffer() throws IOException {
|
||||||
|
|
||||||
|
ChainedBuffer cb = new ChainedBuffer(1, obfuscated, sourceData, sourceDataOffset, mgr);
|
||||||
|
|
||||||
|
// Fill
|
||||||
|
cb.fill(0, 0, (byte) 0x12);
|
||||||
|
|
||||||
|
// Verify data
|
||||||
|
assertEquals(cb.getByte(0), (byte) 0x12);
|
||||||
|
|
||||||
|
// Re-instantiate buffer
|
||||||
|
int id = cb.getId();
|
||||||
|
cb = new ChainedBuffer(mgr, id);
|
||||||
|
|
||||||
|
// Re-verify data
|
||||||
|
assertEquals(cb.getByte(0), (byte) 0x12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChainedBufferOverflow() throws IOException {
|
||||||
|
|
||||||
|
ChainedBuffer cb = new ChainedBuffer(1, obfuscated, sourceData, sourceDataOffset, mgr);
|
||||||
|
|
||||||
|
// Fill too much by 1 byte to test generated exception bounds
|
||||||
|
try {
|
||||||
|
cb.fill(0, 1, (byte) 0x12);
|
||||||
|
}
|
||||||
|
catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("Overflow was not correctly detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBigChainedBuffer() throws IOException {
|
||||||
|
|
||||||
ChainedBuffer cb =
|
ChainedBuffer cb =
|
||||||
new ChainedBuffer(BIG_DATA_SIZE, obfuscated, sourceData, sourceDataOffset, mgr);
|
new ChainedBuffer(BIG_DATA_SIZE, obfuscated, sourceData, sourceDataOffset, mgr);
|
||||||
|
|
Loading…
Reference in a new issue