Comments (2)
Thank you for the report.
What happens here is that the file size (u64) is cast to an int (i32), and then cast to size_t (u32 or u64), so if the ControlData or ResetTable file size claims to be over 2GB, the int will be negative and the memory requested will either be 2-4 gigabytes (32-bit size_t) or 15-16 exabytes (64-bit size_t). It's unlikely this memory request will ever be fulfilled, but if it succeeded, the subsequent read() call would fail and the memory would be deallocated and the file rejected.
However, this report reveals a more concerning issue: when the ControlData or ResetTable file length is less than 2GB, but still a large value, and there is genuinely that much data provided for the file (so read() succeeds), it allows the file creator to make libmspack allocate and use up to 4GB of memory. This is against library user expectations, so the upper limit on memory use for these system files should be quantified.
read_sys_file() is used to read 3 system files into memory: SpanInfo, ControlData and ResetTable. SpanInfo is already rejected if its file length is not exactly 8 bytes.
ControlData is not loaded if its file length is less than 28 bytes, but larger files were allowed in case a new version of the file was introduced. As no new version has been introduced in years, it is much better to reject the file if not exactly 28 bytes. This does not affect any genuine CHM files.
ResetTable can theoretically be huge; the longest possible LZX stream (16 exabytes) could have a 4 petabyte ResetTable. But practically, the largest seen in the wild is 46 kilobytes (PHP manuals). so I picked an arbitrary upper limit of 1MB, which allows for decompressed LZX streams of over 4GB.
This is fixed in commit 2c4bf97, please confirm.
from libmspack.
Thanks for your very detailed analysis!
I have tried the newest commit, this bug has been fixed. Good work!
from libmspack.
Related Issues (20)
- cabextract doesn't build from master HOT 2
- memory exhausted in oabd_decompress() HOT 2
- memory exhausted in chmd_read_headers() HOT 1
- Heap buffer overflow in chmd_read_headers() HOT 7
- Multiple filters in one command HOT 6
- 1.9.1: issue with dist tar ball HOT 2
- Not clear on Github how to get libmspack vs cabextract releases HOT 17
- chmextract HOT 2
- Conflicting definitions for copy_fh HOT 3
- configure / libtool fails with -flto HOT 12
- configure / libtool fails with -flto HOT 6
- Compilier warnings with 1.9.1 HOT 4
- Compiler error with 1.9.1 / gcc 9.3.1 HOT 5
- extra = 0 confusion HOT 4
- build fails on macos HOT 1
- cabextract: Writing into symlinks HOT 11
- Issue with KWAJ method 2 decompression HOT 2
- Fail to properly create path components coming from the archive HOT 3
- Cannot extract files from a .cab file containing file names encoded in shift_JIS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libmspack.