fix(safetensors): conform JSON unicode and whitespace - #79
Conversation
Decode UTF-16 surrogate pairs in escaped strings and restrict structural whitespace to the four characters allowed by RFC 8259. Add coverage for valid round trips and malformed input. Co-authored-by: Codex <noreply@openai.com>
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (3)
🧰 Additional context used📓 Path-based instructions (3)Do **not** add myelin (or CUDA) as a dependency of engram-parser — optional or not.📄 CodeRabbit inference engine (REVIEW.md) Files:
**No CUDA, dequant, mmap, or GGML compute** in this repo.📄 CodeRabbit inference engine (REVIEW.md) Files:
engram-parser never depends on either.📄 CodeRabbit inference engine (REVIEW.md) Files:
🔇 Additional comments (4)
📝 SummarySummary by CodeRabbit
WalkthroughThe JSON parser now decodes valid UTF-16 surrogate pairs, rejects invalid Unicode escapes, limits structural whitespace to RFC 8259 characters, and adds tests for decoding, duplicate keys, round-tripping, and whitespace behavior. ChangesJSON conformance
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The parser now handles Unicode escapes and structural whitespace according to the stated JSON requirements, with no remaining merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit parsed the moonlit code Comment |
User description
Motivation
\uXXXXescapes and limiting structural whitespace to the four characters allowed by the spec.Description
c.is_whitespace()with an explicit match for' ' | '\t' | '\n' | '\r'inskip_whitespaceto match RFC 8259.parse_escaped_unicode_scalarto combine high/low UTF-16 surrogate pairs into the correct Unicode scalar and to reject lone, reversed, truncated, or malformed surrogate sequences.parse_stringso\uescapes produce proper non-BMP characters and malformed escapes surface the existing JSON parse error path.Testing
cargo fmt -- --check, which succeeded.cargo test --locked --features safetensors safetensors::json::tests, and the safetensors JSON tests passed.cargo test --locked --features safetensors, and the safetensors feature test suite passed.cargo test --locked --all-features, and the full test suite completed with all tests passing.Codex Task
Summary by cubic
Fixes the
safetensorsJSON parser to conform to RFC 8259 by decoding UTF-16 surrogate pairs in\uescapes and limiting structural whitespace to the four characters allowed by the spec.' ' | '\t' | '\n' | '\r'so Unicode whitespace no longer acts as a structural separator.Written for commit 29a449a. Summary will update on new commits.
CodeAnt-AI Description
Make Safetensors JSON parsing conform to RFC 8259 for Unicode escapes and whitespace
What Changed
Impact
✅ Correct emoji and other non-BMP characters in parsed JSON✅ Fewer malformed JSON values accepted✅ Consistent duplicate-key detection💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.