mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Merge remote-tracking branch 'origin/GP-5244_ghidra1_FileBytesProviderBugs' into Ghidra_11.3
This commit is contained in:
commit
6c0336443d
2 changed files with 51 additions and 15 deletions
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -67,7 +67,12 @@ public class FileBytesProvider implements ByteProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte readByte(long index) throws IOException {
|
public byte readByte(long index) throws IOException {
|
||||||
return fileBytes.getOriginalByte(index);
|
try {
|
||||||
|
return fileBytes.getOriginalByte(index);
|
||||||
|
}
|
||||||
|
catch (IndexOutOfBoundsException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,7 +89,12 @@ public class FileBytesProvider implements ByteProvider {
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
}
|
}
|
||||||
byte[] bytes = new byte[(int) length];
|
byte[] bytes = new byte[(int) length];
|
||||||
fileBytes.getOriginalBytes(index, bytes);
|
try {
|
||||||
|
fileBytes.getOriginalBytes(index, bytes);
|
||||||
|
}
|
||||||
|
catch (IndexOutOfBoundsException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,18 +115,36 @@ public class FileBytesProvider implements ByteProvider {
|
||||||
private long offset;
|
private long offset;
|
||||||
|
|
||||||
FileBytesProviderInputStream(long offset) {
|
FileBytesProviderInputStream(long offset) {
|
||||||
|
if (offset < 0) {
|
||||||
|
throw new IllegalArgumentException("Negative offset: " + offset);
|
||||||
|
}
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.initialOffset = offset;
|
this.initialOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
byte b = readByte(offset++);
|
if (offset >= length()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
byte b = readByte(offset);
|
||||||
|
++offset;
|
||||||
return b & 0xff;
|
return b & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (off < 0 || off >= b.length) {
|
||||||
|
throw new IllegalArgumentException("Array index out of range: " + off);
|
||||||
|
}
|
||||||
|
long fileBytesLen = length();
|
||||||
|
if (offset >= fileBytesLen) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
long limit = fileBytesLen - offset;
|
||||||
|
if (len > limit) {
|
||||||
|
len = (int) limit; // reduce read length
|
||||||
|
}
|
||||||
byte[] bytes = new byte[len];
|
byte[] bytes = new byte[len];
|
||||||
int count = fileBytes.getOriginalBytes(offset, bytes);
|
int count = fileBytes.getOriginalBytes(offset, bytes);
|
||||||
System.arraycopy(bytes, 0, b, off, count);
|
System.arraycopy(bytes, 0, b, off, count);
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -112,7 +112,8 @@ public class FileBytes {
|
||||||
* @throws IOException if there is a problem reading the database.
|
* @throws IOException if there is a problem reading the database.
|
||||||
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
||||||
*/
|
*/
|
||||||
public synchronized byte getModifiedByte(long offset) throws IOException {
|
public synchronized byte getModifiedByte(long offset)
|
||||||
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getByte(layeredBuffers, offset);
|
return getByte(layeredBuffers, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +124,8 @@ public class FileBytes {
|
||||||
* @throws IOException if there is a problem reading the database.
|
* @throws IOException if there is a problem reading the database.
|
||||||
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
||||||
*/
|
*/
|
||||||
public synchronized byte getOriginalByte(long offset) throws IOException {
|
public synchronized byte getOriginalByte(long offset)
|
||||||
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getByte(originalBuffers, offset);
|
return getByte(originalBuffers, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,8 +137,10 @@ public class FileBytes {
|
||||||
* @param b the byte array to populate.
|
* @param b the byte array to populate.
|
||||||
* @return the number of bytes actually populated.
|
* @return the number of bytes actually populated.
|
||||||
* @throws IOException if there is an error reading from the database
|
* @throws IOException if there is an error reading from the database
|
||||||
|
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
||||||
*/
|
*/
|
||||||
public synchronized int getModifiedBytes(long offset, byte[] b) throws IOException {
|
public synchronized int getModifiedBytes(long offset, byte[] b)
|
||||||
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getBytes(layeredBuffers, offset, b, 0, b.length);
|
return getBytes(layeredBuffers, offset, b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +152,10 @@ public class FileBytes {
|
||||||
* @param b the byte array to populate.
|
* @param b the byte array to populate.
|
||||||
* @return the number of bytes actually populated.
|
* @return the number of bytes actually populated.
|
||||||
* @throws IOException if there is an error reading from the database
|
* @throws IOException if there is an error reading from the database
|
||||||
|
* @throws IndexOutOfBoundsException if the given offset is invalid.
|
||||||
*/
|
*/
|
||||||
public synchronized int getOriginalBytes(long offset, byte[] b) throws IOException {
|
public synchronized int getOriginalBytes(long offset, byte[] b)
|
||||||
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getBytes(originalBuffers, offset, b, 0, b.length);
|
return getBytes(originalBuffers, offset, b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +174,7 @@ public class FileBytes {
|
||||||
* size of the buffer b.
|
* size of the buffer b.
|
||||||
*/
|
*/
|
||||||
public synchronized int getModifiedBytes(long offset, byte[] b, int off, int length)
|
public synchronized int getModifiedBytes(long offset, byte[] b, int off, int length)
|
||||||
throws IOException {
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getBytes(layeredBuffers, offset, b, off, length);
|
return getBytes(layeredBuffers, offset, b, off, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +193,7 @@ public class FileBytes {
|
||||||
* size of the buffer b.
|
* size of the buffer b.
|
||||||
*/
|
*/
|
||||||
public synchronized int getOriginalBytes(long offset, byte[] b, int off, int length)
|
public synchronized int getOriginalBytes(long offset, byte[] b, int off, int length)
|
||||||
throws IOException {
|
throws IOException, IndexOutOfBoundsException {
|
||||||
return getBytes(originalBuffers, offset, b, off, length);
|
return getBytes(originalBuffers, offset, b, off, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +243,10 @@ public class FileBytes {
|
||||||
* @param offset the offset into the file bytes.
|
* @param offset the offset into the file bytes.
|
||||||
* @param b a byte array with the new values to write.
|
* @param b a byte array with the new values to write.
|
||||||
* @return the number of bytes written
|
* @return the number of bytes written
|
||||||
|
* @throws IndexOutOfBoundsException if invalid offset is specified
|
||||||
* @throws IOException if the write to the database fails.
|
* @throws IOException if the write to the database fails.
|
||||||
*/
|
*/
|
||||||
synchronized int putBytes(long offset, byte[] b) throws IOException {
|
synchronized int putBytes(long offset, byte[] b) throws IOException, IndexOutOfBoundsException {
|
||||||
return putBytes(offset, b, 0, b.length);
|
return putBytes(offset, b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +263,8 @@ public class FileBytes {
|
||||||
* @throws IndexOutOfBoundsException if invalid offset is specified
|
* @throws IndexOutOfBoundsException if invalid offset is specified
|
||||||
* @throws IOException if the write to the database fails.
|
* @throws IOException if the write to the database fails.
|
||||||
*/
|
*/
|
||||||
synchronized int putBytes(long offset, byte[] b, int off, int length) throws IOException {
|
synchronized int putBytes(long offset, byte[] b, int off, int length)
|
||||||
|
throws IOException, IndexOutOfBoundsException {
|
||||||
|
|
||||||
checkValid();
|
checkValid();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue