work with number of bytes returned by ReadableFile.read(), Coverity issues 72259 and 72261

This commit is contained in:
Sebastian Stenzel
2016-03-04 01:39:50 +01:00
parent 3a725e4a16
commit 6da3fde864
2 changed files with 7 additions and 4 deletions

View File

@@ -47,10 +47,10 @@ class CiphertextReader implements Callable<Void> {
int bytesRead = -1;
do {
ByteBuffer ciphertext = ByteBuffer.allocate(READ_BUFFER_SIZE);
file.read(ciphertext);
ciphertext.flip();
bytesRead = ciphertext.remaining();
bytesRead = file.read(ciphertext);
if (bytesRead > 0) {
ciphertext.flip();
assert bytesRead == ciphertext.remaining();
decryptor.append(ciphertext);
}
} while (bytesRead > 0);

View File

@@ -43,7 +43,10 @@ class CryptoReadableFile implements ReadableFile {
this.authenticate = authenticate;
this.onAuthError = onAuthError;
file.position(0);
file.read(header);
int headerBytesRead = file.read(header);
if (headerBytesRead != header.capacity()) {
throw new IllegalArgumentException("File too short to contain a header.");
}
header.flip();
this.position(0);
}