Add size check for the read() function

This commit is contained in:
Maschell 2019-05-04 12:26:31 +02:00
parent 5e05c65efd
commit 2c3a5332a4
2 changed files with 12 additions and 2 deletions

View File

@ -116,6 +116,11 @@ public class FSTDataProviderContainer implements FuseContainer {
if (offset + size > entry.getFileSize()) {
size = entry.getFileSize() - offset;
}
if(size > Integer.MAX_VALUE) {
System.err.println("Request read size was too big.");
return -ErrorCodes.EIO();
}
try {
byte[] data = getDataProvider().readFile(entry, offset, size);

View File

@ -197,6 +197,11 @@ public class NUSTitleEncryptedFuseContainer implements FuseContainer {
if (path.equals("/")) {
return -ErrorCodes.EISDIR();
}
if(size > Integer.MAX_VALUE) {
System.err.println("Request read size was too big.");
return -ErrorCodes.EIO();
}
path = path.substring(1);
@ -204,7 +209,7 @@ public class NUSTitleEncryptedFuseContainer implements FuseContainer {
if (coOptional.isPresent()) {
Content c = coOptional.get();
if (offset >= c.getEncryptedFileSize()) {
return -ErrorCodes.ENOENT();
return -ErrorCodes.EIO();
}
if (offset + size > c.getEncryptedFileSize()) {
size = c.getEncryptedFileSize() - offset;
@ -225,7 +230,7 @@ public class NUSTitleEncryptedFuseContainer implements FuseContainer {
byte[] hash = h3Data.get();
if (offset >= hash.length) {
return -ErrorCodes.ENOENT();
return -ErrorCodes.EIO();
}
if (offset + size > hash.length) {
size = hash.length - offset;