Details about the known misuse from the MUBench dataset.
Description:
When a DataOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the DataOutputStream before invoking the underlying instances's toByteArray().
Although in these cases this is not strictly necessary because the
DataOutputStream's close and flush method has no effects. However, it is a good practice to call
flush/close explicitly as mentioned for example here.
This pull request adds a call to close.
class SignaturePrivateKey {
/**
* Converts the key to a byte array
* @return the encoded key
*/
public byte[] getEncoded() {
int numBases = bases.size();
ByteArrayOutputStream os = new ByteArrayOutputStream();
DataOutputStream dataStream = new DataOutputStream(os);
try {
dataStream.writeShort(N);
dataStream.writeShort(q);
int flags = sparse ? 1 : 0;
flags |= polyType==TernaryPolynomialType.PRODUCT ? 4 : 0;
flags |= basisType==BasisType.TRANSPOSE ? 8 : 0;
dataStream.write(flags);
dataStream.writeFloat(keyNormBoundSq);
dataStream.write(numBases); // 1 byte
for (int i=0; i<numBases; i++)
// all bases except for the first one contain a public key
bases.get(i).encode(os, i!=0);
} catch (IOException e) {
throw new NtruException(e);
}
return os.toByteArray();
}
}