You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2023/01/20 06:59:05 UTC
[Bug 66436] New: The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Bug ID: 66436
Summary: The xlsx file created by poi cannot be opened normally
by office software after being encrypted and decrypted
with POIFS
Product: POI
Version: 5.2.2-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: POIFS
Assignee: dev@poi.apache.org
Reporter: 766781886@qq.com
Target Milestone: ---
Created attachment 38474
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38474&action=edit
Test code to demonstrate the issue
The encrypted excel created by Microsoft Excel can be opened normally after
being decrypted by POI. However, the encrypted Excel created by POI cannot be
opened normally by Microsoft Excel after being decrypted by POI.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] Invalid handling of padding causes issues when decrypting encrypted data
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|After the .xlsx file is |Invalid handling of padding
|encrypted by poi and then |causes issues when
|decrypted by POI, an error |decrypting encrypted data
|will be reported when it is |
|opened with Microsoft |
|Excel, and an error will |
|also be reported when it is |
|decompressed with |
|commons-compress |
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
OS| |All
--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
If this was just broken, we would have loads of people reporting it.
There must be something specific in your use case.
* could you provide details of which Excel versions you are testing with
(including the OS)?
* could you provide the original file used in your test code?
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #6 from Tom Xin <76...@qq.com> ---
Created attachment 38478
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38478&action=edit
Excel file created and encrypted by Microsoft Excel.Password:foobaa
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #11 from Tom Xin <76...@qq.com> ---
(In reply to PJ Fanning from comment #10)
> I used Excel on office.com and
> xtemp_excel_microsoftoffice_encrypted_poi_decrypted.xlsx opens fine.
>
> I don't have any other access to Excel.
Maybe you didn't understand the problem correctly, the file that can't be
opened normally is the fourth attachment titled "Excel file created by POI,
then encrypted by POI, then decrypted by POI "
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #2 from Tom Xin <76...@qq.com> ---
Created attachment 38475
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38475&action=edit
Excel file created by POI
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #14 from Tom Xin <76...@qq.com> ---
(In reply to Tom Xin from comment #13)
> Created attachment 38481 [details]
> Test code3
In addition, when parsing the document encrypted and decrypted by POI through
commoms-compress, an exception will be thrown:
java.io.IOException: Error on ZipFile D:\temp_excel_poi_decrypt.xlsx
See the attached "Test code3" for the relevant code, and the attached
"Exception stacktrace" for the error stack information
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #15 from Tom Xin <76...@qq.com> ---
Created attachment 38482
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38482&action=edit
Exception stacktrace
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #8 from Tom Xin <76...@qq.com> ---
Created attachment 38480
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38480&action=edit
Test code2 to demonstrate the issue
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Tom Xin <76...@qq.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |NEW
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #12 from PJ Fanning <fa...@yahoo.com> ---
that is the file I tested - successfully
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #13 from Tom Xin <76...@qq.com> ---
Created attachment 38481
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38481&action=edit
Test code3
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Tom Xin <76...@qq.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #38483|Com |Excel file hexadecimal
description| |comparison using BinEd
--- Comment #17 from Tom Xin <76...@qq.com> ---
Comment on attachment 38483
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38483
Excel file hexadecimal comparison using BinEd
I used BinEd to compare the Excel files and found that the data in the last row
of them is different. So there is reason to suspect that there is an error in
POI's handling of the data stream when decrypting the file.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] After the .xlsx file is encrypted by poi and then decrypted by POI, an error will be reported when it is opened with Microsoft Excel, and an error will also be reported when it is decompressed with commons-compress
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #18 from Dominik Stadler <do...@gmx.at> ---
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #9 from Tom Xin <76...@qq.com> ---
I created new test code to better reproduce the issue, see the attached file
titled 'Test code2 to demonstrate the issue'. I also uploaded all attachments
used/produced in the code.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #16 from Tom Xin <76...@qq.com> ---
Created attachment 38483
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38483&action=edit
Com
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #3 from Tom Xin <76...@qq.com> ---
Created attachment 38476
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38476&action=edit
Excel file created by POI then encrypted by POI.Passwoword:foobaa
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #4 from Tom Xin <76...@qq.com> ---
Created attachment 38477
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38477&action=edit
Excel file created by POI, then encrypted by POI, then decrypted by POI
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #5 from Tom Xin <76...@qq.com> ---
(In reply to PJ Fanning from comment #1)
> If this was just broken, we would have loads of people reporting it.
>
> There must be something specific in your use case.
>
> * could you provide details of which Excel versions you are testing with
> (including the OS)?
> * could you provide the original file used in your test code?
OS:Windows 10 Home Edition
JDK:azul-1.8
Office:Microsoft Office LTSC Professional Plus 2021
POI:I have tested all versions of POI from 5.0.0 to 5.2.3 and have this problem
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] Invalid handling of padding causes issues when decrypting encrypted data
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #20 from Tom Xin <76...@qq.com> ---
(In reply to Dominik Stadler from comment #19)
> This is hopefully now fixed via r1907444
>
> The code seems to not have taken into account that ciphers work on data in
> 16-byte-chunks and so sometimes a bit more data needs to be read.
>
> By trying to read a few bytes more, the test-case and a number of new tests
> now work fine and existing tests continue to work.
>
>
>
> What made it hard to find is that the JDK code silently ignores a chunk of
> data if it's size is not a multiple of 16-bytes and just keeps using the
> encrypted data!?:
>
> From
> /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip!/java.base/com/sun/crypto/
> provider/CipherCore.java:720
>
> // do not count the trailing bytes which do not make up a unit
> len = (len > 0 ? (len - (len % unitBytes)) : 0);
That's great!
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #7 from Tom Xin <76...@qq.com> ---
Created attachment 38479
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38479&action=edit
Excel file created and encrypted by Microsoft Excel,then decrypted by POI
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] The xlsx file created by poi cannot be opened normally by office software after being encrypted and decrypted with POIFS
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
--- Comment #10 from PJ Fanning <fa...@yahoo.com> ---
I used Excel on office.com and
xtemp_excel_microsoftoffice_encrypted_poi_decrypted.xlsx opens fine.
I don't have any other access to Excel.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] After the .xlsx file is encrypted by poi and then decrypted by POI, an error will be reported when it is opened with Microsoft Excel, and an error will also be reported when it is decompressed with commons-compress
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Tom Xin <76...@qq.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|The xlsx file created by |After the .xlsx file is
|poi cannot be opened |encrypted by poi and then
|normally by office software |decrypted by POI, an error
|after being encrypted and |will be reported when it is
|decrypted with POIFS |opened with Microsoft
| |Excel, and an error will
| |also be reported when it is
| |decompressed with
| |commons-compress
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66436] Invalid handling of padding causes issues when decrypting encrypted data
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66436
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #19 from Dominik Stadler <do...@gmx.at> ---
This is hopefully now fixed via r1907444
The code seems to not have taken into account that ciphers work on data in
16-byte-chunks and so sometimes a bit more data needs to be read.
By trying to read a few bytes more, the test-case and a number of new tests now
work fine and existing tests continue to work.
What made it hard to find is that the JDK code silently ignores a chunk of data
if it's size is not a multiple of 16-bytes and just keeps using the encrypted
data!?:
From
/usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip!/java.base/com/sun/crypto/provider/CipherCore.java:720
// do not count the trailing bytes which do not make up a unit
len = (len > 0 ? (len - (len % unitBytes)) : 0);
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org