Check partial file reads on a different location

This commit is contained in:
Maschell 2019-04-26 09:51:28 +02:00
parent 995d548c11
commit 5a57d42c52
2 changed files with 5 additions and 8 deletions

View File

@ -146,7 +146,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
if (c.isHashed()) { if (c.isHashed()) {
h3HashedOpt = dataProvider.getContentH3Hash(c); h3HashedOpt = dataProvider.getContentH3Hash(c);
} }
return nusdecryption.decryptStreams(in, outputStream, fileOffset, fileSize, c, h3HashedOpt); return nusdecryption.decryptStreams(in, outputStream, fileOffset, fileSize, c, h3HashedOpt, fileSize == entry.getFileSize());
} catch (CheckSumWrongException e) { } catch (CheckSumWrongException e) {
if (c.isUNKNWNFlag1Set()) { if (c.isUNKNWNFlag1Set()) {
log.info("Hash doesn't match. But file is optional. Don't worry."); log.info("Hash doesn't match. But file is optional. Don't worry.");

View File

@ -276,8 +276,8 @@ public class NUSDecryption extends AESDecryption {
return output; return output;
} }
public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed) public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed,
throws IOException, CheckSumWrongException, NoSuchAlgorithmException { boolean partial) throws IOException, CheckSumWrongException, NoSuchAlgorithmException {
short contentIndex = (short) content.getIndex(); short contentIndex = (short) content.getIndex();
@ -290,11 +290,8 @@ public class NUSDecryption extends AESDecryption {
decryptFileStreamHashed(inputStream, outputStream, offset, size, (short) contentIndex, h3); decryptFileStreamHashed(inputStream, outputStream, offset, size, (short) contentIndex, h3);
} else { } else {
byte[] h3Hash = content.getSHA2Hash(); byte[] h3Hash = content.getSHA2Hash();
// We want to check if we read the whole file or just a part of it. // Ignore the h3hash if we don't read the whole file.
// There should be only one actual file inside a non-hashed content. if (partial) {
// But it could also contain a directory, so we need to filter.
long fstFileSize = content.getEntries().stream().filter(f -> !f.isDir()).findFirst().map(f -> f.getFileSize()).orElse(0L);
if (size > 0 && size < fstFileSize) {
h3Hash = null; h3Hash = null;
} }
decryptFileStream(inputStream, outputStream, offset, size, (short) contentIndex, h3Hash, encryptedFileSize); decryptFileStream(inputStream, outputStream, offset, size, (short) contentIndex, h3Hash, encryptedFileSize);