Repository navigation
[fix] Fixed truncation of non-ASCII file contents in generated tar #341 - #419
Conversation
…enwisp#341 The size of each tar member was set to the number of characters in the file contents instead of the length of its UTF-8 encoding, so any file containing multi-byte characters (for example an Arabic SSID in /etc/config/wireless) was cut short when the archive was extracted. Closes openwisp#341
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📜 Recent review details🧰 Additional context used📓 Path-based instructions (3)Ensure tests cover relevant success, error, boundary, and unusual input scenarios.⚙️ CodeRabbit configuration file Files:
Flag potential security vulnerabilities Flag obvious performance regressions, such as heavy loops, repeated I/O, or unoptimized queries Flag unused or redundant code Flag outdated or incorrect comments/docstrings Ensure new code handles err...⚙️ CodeRabbit configuration file Files:
Source excerpt: Keep tests quiet on success.📄 CodeRabbit inference engine (AGENTS.md) Files:
🔇 Additional comments (1)
📝 WalkthroughWalkthrough
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The archive now declares the byte length of its UTF-8 content, and the OpenWrt regression test checks that a non-ASCII SSID survives generation. No merge-blocking issue is evident. Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (4 passed)
Full details: Ui Changes, Regression Test, DocsExplanation The PR fixes generated archive content, a behavior of the documented OpenWrt
Comment |
|
Proposed change log entry: |
|
/backport 1.3 |
Checklist
Reference to Existing Issue
Closes #341.
Description of Changes
Any non-ASCII text in a generated config file comes out truncated in the tar.gz produced by
generate(). The reporter hit this with Arabic SSIDs on OpenWrt:/etc/config/wirelessends up cut off in the middle of the SSID and uci then refuses to parse the file.The cause is in
BaseBackend._add_file, as momothefox already worked out in the issue thread. It writescontents.encode('utf8')into the archive but sets the tar member size tolen(contents), which is the number of characters, not the number of bytes. For plain ASCII the two are equal, so nothing looked wrong until someone used multi-byte characters. Everything past the declared size is silently dropped when the archive is extracted.The fix encodes the contents once and uses the length of the encoded bytes for
info.size.I added
test_generate_multibyte_contentsto the OpenWrt backend tests. It generates an archive with an Arabic SSID and afilesentry containing CJK and accented characters, then checks that the extracted wireless config contains the whole SSID and that the extra file's declared size and contents match its UTF-8 bytes. The test fails on master and passes with this change.Tested locally on Python 3.13 with the full suite (
coverage run runtests.py, 629 tests) and./run-qa-checks. I also checked it by hand with a small script that generates the archive and reads the members back: before the fix the wireless member was declared as 257 bytes and ended atoption ssid 'محمدين و, after the fix it is 269 bytes and contains the full SSID.Screenshot
N/A