Fix ESP32 hard reset from binary garbage in HTTP header logging #2236
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix ESP32 Hard Reset from Binary Garbage in HTTP Header Logging
Summary
Prevents ESP32 hard resets when HTTP servers send malformed headers with binary garbage. Replaces unsafe
%slogging with four-layer safety approach that sanitizes buffers, uses hex dumps, and prevents parser corruption.Problem Description
Symptom
ESP32 immediately hard-resets with no crash log or backtrace when playing certain internet radio streams that send corrupted HTTP headers.
Real-World Trigger
Root Cause
File:
src/AudioTools/Communication/HTTP/HttpLineReader.h:75When HTTP headers exceed the 1024-byte buffer limit, the original code logs:
This causes immediate ESP32 hard resets because:
Serial.printf()bufferSolution
Four-Layer Safety Approach
Sanitize actual buffer in-place (prevents parser poisoning)
Count printable vs non-printable (smart detection)
Hex dump for binary data (safer than string masking)
256-byte output limit (prevents log spam)
Code Changes
File:
src/AudioTools/Communication/HTTP/HttpLineReader.hLines: 73-140
Impact
Before
After
Testing
Test Environments
Test Results
✅ citrus3.com (original crash trigger): Safe logging, system continues
✅ Normal stations (20,308 tested): No behavioral changes, zero overhead
✅ Long headers (>1024 bytes): Truncated safely with byte count
✅ Build size: +260 bytes Flash (minimal overhead)
✅ Memory: No additional RAM usage
Example Output (Binary Garbage)
Example Output (Truncated Text)
Security Review
This fix was peer-reviewed by GPT-4 and addresses all identified concerns:
✅ Correctness: Removes dangerous %s logging, replaces with bounded output
✅ Parser Safety: In-place sanitization prevents downstream header corruption
✅ Output Limits: 256-byte cap on logging, 32-byte hex dumps prevent spam
✅ Hex Dump: Industry-standard approach for unknown binary data
✅ UTF-8 Safe: Non-ASCII bytes replaced with spaces, no encoding issues
✅ Maintainability: Clear comments, documented real-world trigger case
Backward Compatibility
Checklist
References
FORK_CHANGES.mdfor complete analysisAuthor: rwb (ESP32-SD-TLV320DAC3100 project)
Testing: 8+ hours of multi-station streaming, 20,308 station database validation
Review: GPT-4 security analysis (passed all checks)