You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(readme): document security features and parsing limits
- Add production-safe parser and security hardening feature descriptions
- Document configurable safety limits for depth, array size, string length, and map size
- Add security architecture section explaining iterative parsing and memory safety
- Update API overview with PackWithLimits and ParseLimits documentation
- Expand test suite and benchmark documentation with comprehensive details
- Fix error naming from MsGPackError to MsgPackError for consistency
- Improve markdown table formatting and clean up trailing whitespace
Copy file name to clipboardExpand all lines: README.md
+92-11Lines changed: 92 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ An article introducing it: [Zig Msgpack](https://blog.nvimer.org/2025/09/20/zig-
10
10
11
11
-**Full MessagePack Support:** Implements all MessagePack types including the timestamp extension.
12
12
-**Timestamp Support:** Complete implementation of MessagePack timestamp extension type (-1) with support for all three formats (32-bit, 64-bit, and 96-bit).
13
+
-**Production-Safe Parser:** Iterative parser prevents stack overflow on deeply nested or malicious input.
14
+
-**Security Hardened:** Configurable limits protect against DoS attacks (depth bombs, size bombs, etc.).
13
15
-**Efficient:** Designed for high performance with minimal memory overhead.
14
16
-**Type-Safe:** Leverages Zig's type system to ensure safety during serialization and deserialization.
15
17
-**Simple API:** Offers a straightforward and easy-to-use API for encoding and decoding.
@@ -18,12 +20,12 @@ An article introducing it: [Zig Msgpack](https://blog.nvimer.org/2025/09/20/zig-
18
20
19
21
### Version Compatibility
20
22
21
-
| Zig Version | Library Version | Status |
22
-
|-------------|----------------|---------|
23
-
| 0.13 and older | 0.0.6 | Legacy support |
24
-
| 0.14.0 | Current | ✅ Fully supported |
25
-
| 0.15.x | Current | ✅ Fully supported |
26
-
| 0.16.0-dev (nightly) | Current | ✅ Supported with compatibility layer |
| 0.16.0-dev (nightly) | Current | ✅ Supported with compatibility layer |
27
29
28
30
> **Note:** For Zig 0.13 and older versions, please use version `0.0.6` of this library.
29
31
> **Note:** Zig 0.16+ removes `std.io.FixedBufferStream`, but this library provides a compatibility layer to maintain the same API across all supported versions.
- ✅ **Bounded memory usage** with configurable limits
202
+
- ✅ **Fast rejection** of invalid data (no resource exhaustion)
203
+
204
+
Possible security errors:
205
+
206
+
```zig
207
+
msgpack.MsgPackError.MaxDepthExceeded // Nesting too deep
208
+
msgpack.MsgPackError.ArrayTooLarge // Array claims too many elements
209
+
msgpack.MsgPackError.MapTooLarge // Map claims too many pairs
210
+
msgpack.MsgPackError.StringTooLong // String/binary data too large
211
+
```
212
+
165
213
## API Overview
166
214
167
-
- **`msgpack.Pack`**: The main struct for packing and unpacking MessagePack data. It is initialized with read and write contexts.
215
+
- **`msgpack.Pack`**: The main struct for packing and unpacking MessagePack data with default safety limits.
216
+
- **`msgpack.PackWithLimits`**: Create a packer with custom safety limits for specific security requirements.
168
217
- **`msgpack.Payload`**: A union that represents any MessagePack type. It provides methods for creating and interacting with different data types (e.g., `mapPayload`, `strToPayload`, `mapGet`).
218
+
- **`msgpack.ParseLimits`**: Configuration struct for parser safety limits.
169
219
170
220
## Implementation Notes
171
221
222
+
### Security Architecture
223
+
224
+
This library uses an **iterative parser** (not recursive) to provide strong security guarantees:
225
+
226
+
**Iterative Parsing:**
227
+
228
+
- Parser uses an explicit stack (on heap) instead of recursive functioncalls
229
+
- Stack depth remains constant regardless of input nesting depth
230
+
- Prevents stack overflow attacks completely
231
+
232
+
**Safety Limits:**
233
+
234
+
- All limits are enforced **before** memory allocation
235
+
- Invalid input is rejected immediately without resource consumption
236
+
- Configurable limits allow tuning for specific environments (embedded, server, etc.)
237
+
238
+
**Memory Safety:**
239
+
240
+
- All error paths include complete cleanup (`errdefer` + `cleanupParseStack`)
241
+
- Zero memory leaks verified by GPA (General Purpose Allocator) in tests
242
+
- Safe to parse untrusted data from network, files, or user input
243
+
172
244
### Zig 0.16 Compatibility
173
245
174
246
Starting from Zig 0.16, the standard library underwent significant changes to the I/O subsystem. The `std.io.FixedBufferStream` was removed as part of a broader redesign. This library includes a compatibility layer (`src/compat.zig`) that:
@@ -190,6 +262,14 @@ zig build test
190
262
zig build test --summary all
191
263
```
192
264
265
+
The comprehensive test suite includes:
266
+
267
+
- **87 tests** covering all functionality
268
+
- **Malicious data tests:** Verify protection against crafted attacks (billion-element arrays, extreme nesting, etc.)
269
+
- **Fuzz tests:** Random input validation ensures no crashes on arbitrary data
270
+
- **Large data tests:** Arrays with 1000+ elements, maps with 500+ pairs
271
+
- **Memory safety:** Zero leaks verified by strict allocator testing
0 commit comments