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

   ### Description
   
   `VBAMacroReader.processDirStream` keys `ModuleMap` by `pair.ascii()` (the 
`MODULESTREAMNAME` record's MBCS `StreamName` decoded with the project 
charset), whereas the second pass in `readMacros` looks up each module stream 
in `ModuleMap` using `entry.getName()`, which is the compound file directory 
entry's UTF-16 name:
   
   - `VBAMacroReader.java` (`MODULE_STREAM_NAME`): assigns `streamName = 
pair.ascii();`
   - `VBAMacroReader.java` (`readMacros` / `readModuleFromDocumentStream`): 
looks up `modules.get(entry.getName())`
   - `VBAMacroReader.java` (`getModule`): translates MBCS names from `PROJECT` 
through `PROJECTwm` into Unicode before calling `moduleMap.get(...)`
   
   Per [MS-OVBA 2.3.4.2.3.2.3 (MODULESTREAMNAME 
Record)](https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-ovba/62cdf46f-c1dc-4b88-aab8-a24c359d13a1),
 `StreamNameUnicode` MUST contain the UTF-16 encoding of `StreamName`. Per 
[MS-CFB 2.6.1 (Compound File Directory 
Entry)](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/60fe8611-66c3-496b-b70d-a504c94c9ace),
 compound file stream entry names are UTF-16.
   
   Whenever decoding the MBCS `StreamName` does not produce the exact UTF-16 
stream name (for example, Windows-31J NEC/IBM extension characters such as `髙` 
or `①` under code page 932, Arabic module names under code page 1256, or 
unmappable MBCS bytes), `modules.get(entry.getName())` misses:
   
   1. `readModuleFromDocumentStream` inserts a second `ModuleImpl` containing 
raw RLE-compressed bytes (with `offset == null`).
   2. The original `ModuleImpl` created from `dir` keeps `buf == null`.
   3. `readMacros()` throws `NullPointerException` when calling 
`ModuleImpl.getContent()` (`new String(buf, charset)`).
   
   ### Steps to reproduce
   
   Construct a `POIFSFileSystem` with a `VBA/dir` stream whose 
`MODULESTREAMNAME` record has `StreamNameUnicode = "\u9ad9\u6a4b\u2460"` 
(UTF-16LE) and an MBCS `StreamName` that decodes to a different string (for 
example `"???"`), alongside a `VBA/\u9ad9\u6a4b\u2460` module stream, and call 
`new VBAMacroReader(fs).readMacros()`.
   
   ### Expected behavior
   
   `processDirStream` uses `pair.unicode()` when non-empty (falling back to 
`pair.ascii()` only if `pair.unicode()` is empty), so `readMacros()` and 
`readMacroModules()` match the UTF-16 compound file stream entry and 
`PROJECTwm` mapping.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to