Fix DataDescriptorStream infinite loop on signature boundary match#1175
Fix DataDescriptorStream infinite loop on signature boundary match#1175Copilot wants to merge 4 commits into
Conversation
When the first byte of the data descriptor signature (0x50 = 'P') appears as the last byte of a read buffer, the reader would rewind and re-read the same byte repeatedly, causing an infinite loop. The fix tracks the last rewind position and prevents rewinding to the same position twice, breaking the infinite loop while preserving correct behavior. Fixes boundary condition where signature bytes at buffer edge cause hang. Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
|
@copilot make a test for the situation described |
Test reproduces the infinite loop scenario where:
- ZIP file contains data filled with 0x50 ('P') bytes
- Non-seekable stream triggers DataDescriptorStream usage
- Partial signature matches at buffer boundaries caused infinite rewind loop
The test verifies that with the fix in place, extraction completes
successfully without hanging. It includes safeguards to detect if the
infinite loop condition occurs (> 1000 read iterations for 100KB file).
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Added regression test in commit e896179. The test reproduces the boundary bug scenario:
The test passes with the fix and would fail with the infinite loop before the fix. |
|
This fixes the case where part of the data descriptor is included in the extracted data. However, if the actual data descriptor is split at the end of the buffer, it will no longer be detected. |
|
@copilot see this:
|
Previous fix prevented infinite loops but broke detection of legitimate data descriptor signatures split across buffer boundaries. New approach: - Track previous rewind count in _previousSearchPosition - Detect infinite loop when read size equals previous rewind count AND all bytes match the signature pattern - In that case, treat bytes as data (not signature) to break loop - Otherwise, allow normal rewind/match to continue for legitimate cross-boundary signatures This fixes both cases: 1. Infinite loop on data containing signature-like bytes (0x50...) 2. Correct detection of actual signatures split at buffer edge Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Fixed in commit c994a9f. The previous fix broke legitimate cross-boundary signature detection. The new approach:
This correctly handles both:
|
Fix DataDescriptorStream boundary bug when signature starts at buffer edge
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.