https://bz.apache.org/bugzilla/show_bug.cgi?id=66436

--- Comment #18 from Dominik Stadler <[email protected]> ---
I could narrow this down to the following test-case and the following findings:

* The length of the byte[] is related, e.g. using 4000 bytes works, but 3292
like here fails
* The actual byte-data seems unrelated, i.e. it fails both when filling the
byte-array with data and also when leaving it empty
* It might be related to some padding, using byte-size 3280 and 3296 make it
work
* It also reproduces with byte-arrays length of 16 (works) and 17 (does not
work)


class TestAgileEncryptor {
    @Test
    void testAgileEncryptor() throws Exception {
        byte[] testData = new byte[3292];

        EncryptionInfo infoEnc = new EncryptionInfo(EncryptionMode.agile);
        Encryptor enc = infoEnc.getEncryptor();
        enc.confirmPassword("foobaa");

        byte[] inputData;
        try (POIFSFileSystem fsEnc = new POIFSFileSystem()) {
            try (OutputStream os = enc.getDataStream(fsEnc)) {
                os.write(testData);
            }

            UnsynchronizedByteArrayOutputStream bos = new
UnsynchronizedByteArrayOutputStream();
            fsEnc.writeFilesystem(bos);

            bos.close();
            inputData = bos.toByteArray();
        }

        byte[] actualData;
        try (POIFSFileSystem fsDec = new POIFSFileSystem(new
ByteArrayInputStream(inputData))) {
            EncryptionInfo infoDec = new EncryptionInfo(fsDec);
            Decryptor dec = infoDec.getDecryptor();
            boolean passed = dec.verifyPassword("foobaa");
            assertTrue(passed);
            InputStream is = dec.getDataStream(fsDec);
            actualData = IOUtils.toByteArray(is);
            is.close();
        }

        assertArrayEquals(testData, actualData,
                "Having " + testData.length + " bytes");
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to