Skip to content

Commit

Permalink
Merge pull request #361 from BezrukovM/decode-fix
Browse files Browse the repository at this point in the history
Fixed skip spaces after RD for type1 private parser
  • Loading branch information
BezrukovM authored Jul 18, 2018
2 parents 95701cc + a0979d1 commit 5a0feca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public int read(byte[] buffer, int size) throws IOException {
this.getInputStream().skip(16);
this.haveReadStream = true;
}
int readDecrypted = this.readFromDecryptedBytes(buffer, size);
if (readDecrypted == -1) {
int readDecrypted = this.readFromDecryptedBytes(buffer, 0, size);
if (readDecrypted >= size) {
return readDecrypted;
}

if (this.bufferSize() <= 0) {
int bytesFed = (int) this.feedBuffer(getBufferCapacity());
if (bytesFed == -1) {
return -1;
return readDecrypted;
}
}
byte[] encData = new byte[BF_BUFFER_SIZE];
Expand All @@ -112,7 +112,11 @@ public int read(byte[] buffer, int size) throws IOException {
byte[] fin = this.aes.doFinal();
this.decryptedBytes = concatenate(this.decryptedBytes,
decryptedBytes.length, fin, fin.length);
return this.readFromDecryptedBytes(buffer, size);
if (readDecrypted == -1) {
return this.readFromDecryptedBytes(buffer, 0, size);
} else {
return readDecrypted + this.readFromDecryptedBytes(buffer, readDecrypted, size - readDecrypted);
}
} catch (GeneralSecurityException e) {
throw new IOException("Can't decrypt AES data.");
}
Expand Down Expand Up @@ -159,12 +163,12 @@ private byte[] getAESInitializingVector() throws IOException {
return initVector;
}

private int readFromDecryptedBytes(byte[] buffer, int size) {
private int readFromDecryptedBytes(byte[] buffer, int from, int size) {
if (decryptedBytes.length == decryptedPointer) {
return -1;
}
int actualRead = Math.min(size, decryptedBytes.length - decryptedPointer);
System.arraycopy(decryptedBytes, decryptedPointer, buffer, 0, actualRead);
System.arraycopy(decryptedBytes, decryptedPointer, buffer, from, actualRead);
decryptedPointer += actualRead;
return actualRead;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ protected boolean processNextOperator(int firstByte) throws IOException {
popStack(6);
break;
case 16: // callothersubr
// TODO: implement call other subr
break;
case 17: // pop
//TODO: should we parse this?
popStack(1);
break;
case 7: // sbw
popStack(1);
Expand Down

0 comments on commit 5a0feca

Please sign in to comment.