fix: remove invalid file length check

- NBT is stored at the end of the clipboard file
 - Fixes #2209
This commit is contained in:
dordsor21 2023-05-10 17:27:44 +01:00
parent 2987550e9b
commit dd6197922c
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -173,7 +173,6 @@ public class DiskOptimizedClipboard extends LinearClipboard {
nbtMap = new HashMap<>();
try {
this.file = file;
checkFileLength(file);
this.braf = new RandomAccessFile(file, "rw");
braf.setLength(file.length());
this.nbtBytesRemaining = Integer.MAX_VALUE - (int) file.length();
@ -202,32 +201,6 @@ public class DiskOptimizedClipboard extends LinearClipboard {
}
}
private void checkFileLength(File file) throws IOException {
long expectedFileSize = headerSize + ((long) getVolume() << 1);
if (file.length() > Integer.MAX_VALUE) {
if (expectedFileSize >= Integer.MAX_VALUE) {
throw new IOException(String.format(
"Cannot load clipboard of file size: %d > 2147483647 bytes (2.147 GiB), " + "volume: %d blocks",
file.length(),
getVolume()
));
} else {
throw new IOException(String.format(
"Cannot load clipboard of file size > 2147483647 bytes (2.147 GiB). Possible corrupt file? Mismatch" +
" between volume `%d` and file length `%d`!",
file.length(),
getVolume()
));
}
} else if (expectedFileSize != file.length()) {
throw new IOException(String.format(
"Possible corrupt clipboard file? Mismatch between expected file size `%d` and actual file size `%d`!",
expectedFileSize,
file.length()
));
}
}
/**
* Attempt to load a file into a new {@link DiskOptimizedClipboard} instance. Will attempt to recover on version mismatch
* failure.