mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-26 08:56:54 +00:00
Fix MemoryMount using incorrect file lengths
- We checked the backing array when reading rather than the file's length, so could read beyond the end of the file. - We used the entry length when resizing, which effectively meant we doubled the size of the backing array on each write.
This commit is contained in:
parent
8db5c6bc3a
commit
f14cb2a3d1
@ -275,9 +275,9 @@ public final class MemoryMount extends AbstractInMemoryMount<MemoryMount.FileEnt
|
|||||||
checkClosed();
|
checkClosed();
|
||||||
|
|
||||||
var backing = Nullability.assertNonNull(entry.contents);
|
var backing = Nullability.assertNonNull(entry.contents);
|
||||||
if (position >= backing.length) return -1;
|
if (position >= entry.length) return -1;
|
||||||
|
|
||||||
var remaining = Math.min(backing.length - (int) position, destination.remaining());
|
var remaining = Math.min(entry.length - (int) position, destination.remaining());
|
||||||
destination.put(backing, (int) position, remaining);
|
destination.put(backing, (int) position, remaining);
|
||||||
position += remaining;
|
position += remaining;
|
||||||
return remaining;
|
return remaining;
|
||||||
@ -285,7 +285,7 @@ public final class MemoryMount extends AbstractInMemoryMount<MemoryMount.FileEnt
|
|||||||
|
|
||||||
private byte[] ensureCapacity(int capacity) {
|
private byte[] ensureCapacity(int capacity) {
|
||||||
var contents = Nullability.assertNonNull(entry.contents);
|
var contents = Nullability.assertNonNull(entry.contents);
|
||||||
if (capacity >= entry.length) {
|
if (capacity >= contents.length) {
|
||||||
var newCapacity = Math.max(capacity, contents.length << 1);
|
var newCapacity = Math.max(capacity, contents.length << 1);
|
||||||
contents = entry.contents = Arrays.copyOf(contents, newCapacity);
|
contents = entry.contents = Arrays.copyOf(contents, newCapacity);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user