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

@ -117,6 +117,11 @@ public class FSTDataProviderContainer implements FuseContainer {
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

@ -198,13 +198,18 @@ public class NUSTitleEncryptedFuseContainer implements FuseContainer {
return -ErrorCodes.EISDIR();
}
if(size > Integer.MAX_VALUE) {
System.err.println("Request read size was too big.");
return -ErrorCodes.EIO();
}
path = path.substring(1);
Optional<Content> coOptional = getContentForPath(path);
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;