https://bz.apache.org/bugzilla/show_bug.cgi?id=65877
Bug ID: 65877
Summary: Error while trying open a write protected xls file
Product: POI
Version: 5.2.0-FINAL
Hardware: PC
Status: NEW
Severity: critical
Priority: P2
Component: HSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Hi Team,
We are trying to parser protected xls files(files which can be opened in
read-only mode using MS Excel Any version),with out the password.
These files are transferred during FTP and program tries to read the files as
it comes.
While using the HSSF framework we are getting below error.
We also observed that if files are opened once using any native app (E.g. MS
Excel), before feeding it to program we are able to read the file successfully.
org.apache.poi.util.RecordFormatException: Unable to construct record instance
at
org.apache.poi.hssf.record.RecordFactory$ReflectionConstructorRecordCreator.create(RecordFactory.java:94)
at
org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:339)
at
org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:289)
at
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:255)
at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:488)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:343)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:306)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:258)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:241)
at
com.highradius.arpa.textextraction.ExcelReadUsingPoi.readV1(ExcelReadUsingPoi.java:31)
at
com.highradius.arpa.textextraction.ExcelReadUsingPoi.main(ExcelReadUsingPoi.java:20)
Caused by: java.lang.IllegalArgumentException: Name is too long:
5??i??$????+???? &
H???4|?|?o???????0??%Z[=?[/h???>?I8v??|/"?\f???.?[?????Z?????v?V???R???5?
at
org.apache.poi.hssf.record.WriteAccessRecord.setUsername(WriteAccessRecord.java:107)
at
org.apache.poi.hssf.record.WriteAccessRecord.<init>(WriteAccessRecord.java:75)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at
org.apache.poi.hssf.record.RecordFactory$ReflectionConstructorRecordCreator.create(RecordFactory.java:84)
Code :
private static void readPOIV1(File file) throws FileNotFoundException,
IOException {
HSSFWorkbook wbxls = null; // for xls
System.out.println("readPOIV1 Trying to read file - " +
file.getAbsolutePath());
POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream(file));
wbxls = new HSSFWorkbook(fs);
String readValue =
wbxls.getSheetAt(1).getRow(0).getCell(1).getStringCellValue();
System.out.println("readPOIV1 Read value from sheet#1 row#1
col#B - " + readValue);
}
On Further analysis we saw
In a scenario where the file is directly fed to the program, the poi framework
tries to intialize the WriteAccessRecord , and in function setUsername it fails
as it tries to use the hashed version of the user name.
It fails as there is a limit to the username length which is
WriteAccessRecord.DATA_SIZE
We suggest to correct the logic and set a dummy user name , incase its not able
to figure out the user name.
--
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]