You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "lurongjiang (via GitHub)" <gi...@apache.org> on 2026/04/07 10:01:59 UTC

[I] Cannot parse DOC files created by WPS Office [poi]

lurongjiang opened a new issue, #1041:
URL: https://github.com/apache/poi/issues/1041

   
   ## Description
   
   DOC files created by WPS Office (Kingsoft Office) cannot be parsed by Apache POI. The files have valid OLE2 headers (`D0 CF 11 E0`) and are detected as `application/msword` by Tika, but POI throws `IndexOutOfBoundsException: Block XX not found` when attempting to parse them.
   
   ## Steps to Reproduce
   
   1. Obtain a DOC file created by WPS Office (sample file attached)
   2. Try to parse the file using POI HWPFDocument or Tika
   
   Example code:
   ```java
   try (FileInputStream fis = new FileInputStream("sample.doc")) {
       HWPFDocument document = new HWPFDocument(fis);
       WordExtractor extractor = new WordExtractor(document);
       String text = extractor.getText();
   } catch (Exception e) {
       e.printStackTrace();
   }
   ```
   
   ## Expected Behavior
   
   The DOC file should be parsed successfully, returning the document text content.
   
   ## Actual Behavior
   
   ```
   java.lang.IndexOutOfBoundsException: Block 52 not found
       at org.apache.poi.poifs.filesystem.POIFSFileSystem.getBlockAt(POIFSFileSystem.java:474)
       ...
   Caused by: java.lang.IndexOutOfBoundsException: Unable to read 512 bytes from 27136 in stream of length 26750
   ```
   
   ## File Analysis
   
   ### File Header
   - File size: 26,750 bytes
   - Magic bytes: `D0 CF 11 E0 A1 B1 1A E1` (valid OLE2 signature)
   - Tika detects as: `application/msword`
   
   ### OLE2 Structure (from header)
   ```
   Offset 0x00: D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00
   Offset 0x10: 00 00 00 00 00 00 00 00 3E 00 03 00 FE FF 09 00
   Offset 0x20: 06 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00
   Offset 0x30: 01 00 00 00 00 00 00 00 00 10 00 00 02 00 00 00
   Offset 0x40: 01 00 00 00 FE FF FF FF 00 00 00 00 00 00 00 00
   ```
   
   - FAT size: 1 byte
   - FAT block count: 1
   - First FAT sector ID: 0
   - MiniFAT block count: -2 (0xFFFFFFFE)
   
   ### WPS Signature Found
   The file contains WPS-specific metadata:
   - `WPS Office_11.1.0.10009`
   - `KSOTemplate`
   - `KSOProductBuildVer`
   
   ### Comparison with WPS "Save As" Fixed File
   When the same file is saved again using WPS (Save As -> doc), the new file:
   - Size: 25,536 bytes (reduced by 1,214 bytes)
   - Header: **Identical** to original file
   - Can be parsed successfully by POI
   
   This indicates the issue is in the internal OLE2 structure (FAT chain), not the file header.
   
   ## Environment
   
   - Apache POI version: [5.2.5,5.5.1]
   - Java version: 1.8
   
   
   ## Additional Notes
   
   1. **WPS Office can directly open and edit these files** - no issues
   2. When using WPS "Save As" (without any modification, just save to same format), POI can parse the resulting file successfully
   
   
   
   [22.doc](https://github.com/user-attachments/files/26533683/22.doc)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4208001098

   @lurongjiang I only have access to use Microsoft via outlook.com and it refuses to load issue_1041.doc because it says it is corrupt.
   This is a WPS issue as far as I am concerned.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "lurongjiang (via GitHub)" <gi...@apache.org>.
lurongjiang commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4198445850

   @pjfanning 
   Thank you very much for your replies! I understand the challenges the POI project faces in handling older file formats. Does POI have any plans to enhance its parsing capabilities for older formats like doc in the future?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4200271925

   Someone might have a look. No plans means that there are no enhancements or coordinated tasks planned. It is possible that someone would take on a bug fix task.
   
   The preference is for the person who is affected by the bug to try to fix it themselves but if that won't happen, someone else may try.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4198325616

   POI is a volunteer project and there is
   * not really anyone with expertise in the old legacy formats
   * there is a bit more expertise in formats like docx and these have been what Microsoft have encouraged users to use for getting on for 20 years
   
   You can have a look yourself and the changes can be reviewed by the POI team.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "lurongjiang (via GitHub)" <gi...@apache.org>.
lurongjiang closed issue #1041: Cannot parse DOC files created by WPS Office
URL: https://github.com/apache/poi/issues/1041


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4198508062

   There are no plans for the older formats.
   This project is purely in maintenance mode.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "lurongjiang (via GitHub)" <gi...@apache.org>.
lurongjiang closed issue #1041: Cannot parse DOC files created by WPS Office
URL: https://github.com/apache/poi/issues/1041


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Cannot parse DOC files created by WPS Office [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1041:
URL: https://github.com/apache/poi/issues/1041#issuecomment-4207917993

   Full stack trace looks like
   ```
   java.lang.IndexOutOfBoundsException: Block 52 not found
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.POIFSFileSystem.getBlockAt(POIFSFileSystem.java:474)
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.POIFSStream$StreamBlockByteBufferIterator.next(POIFSStream.java:212)
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.POIFSStream$StreamBlockByteBufferIterator.next(POIFSStream.java:188)
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.DocumentInputStream.readFully(DocumentInputStream.java:289)
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.DocumentInputStream.read(DocumentInputStream.java:182)
   	at org.apache.poi.poi/org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:271)
   	at org.apache.poi.poi/org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:216)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.HWPFDocumentCore.getDocumentEntryBytes(HWPFDocumentCore.java:409)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.HWPFDocumentCore.<init>(HWPFDocumentCore.java:233)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:302)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:283)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:253)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.extractor.WordExtractor.<init>(WordExtractor.java:71)
   	at org.apache.poi.scratchpad/org.apache.poi.hwpf.extractor.TestWordExtractor.testWpsDocByFs(TestWordExtractor.java:448)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
   	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
   	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
   	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
   	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
   	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
   Caused by: java.lang.IndexOutOfBoundsException: Unable to read 512 bytes from 27136 in stream of length 26750
   	at org.apache.poi.poi/org.apache.poi.poifs.nio.FileBackedDataSource.read(FileBackedDataSource.java:100)
   	at org.apache.poi.poi/org.apache.poi.poifs.filesystem.POIFSFileSystem.getBlockAt(POIFSFileSystem.java:472)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org