Urgent.News

What's breaking now, across thousands of outlets.

Tech

Implementing FMA and finding bugs in C and Rust standard libraries

The standard library alone is insufficient for guaranteed JSON validation in Rust. After spending a weekend building a JSON toolkit with zero external dependencies, I discovered that 10% of JSON documents rejected by RFC 8259 are still accepted by Rust's default number parsing. Examples include NaN, Infinity, 5., .5, +1, and 012.

These invalid JSON elements are accepted by functions like f64::from_str and i64::from_str, which do not enforce the strict JSON specification. My JSON parser, jaq-lite, supports a range of JSON features while maintaining compliance with RFC 8259. It includes identity, field access, indexed access, iteration, pipes, commas, parentheses, the optional operator ?, and eleven built-in functions.

Exit codes from jaq-lite follow the jq standard: 2 for bad flags, 3 for uncompiled filters, 5 for non-JSON input, and 0 for successful execution. The JSONTestSuite is used as the standard conformance corpus, containing 318 parsing files and 35 invalid number cases. Delegating validation to Rust's standard library's from_str function proved inadequate, as it accepted nineteen invalid JSON number literals without error messages or warnings.

The issue lies in the conversion function's permissive nature, not in Rust itself. Consequently, when exchanging JSON data with Python or JavaScript services, it is essential to handle potential validation discrepancies.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at shnatsel.github.io →

More in Tech

What an Embeddable Paycheck Calculator Taught Me About Iframes, Privacy, and Honest UX

Most “embed this tool” features are really small integration projects: install a script, create an account, obtain a key, add a container, and hope the host site's CSS does not win a specificity…

  • Embeddable Paycheck Calculator uses iframes for seamless integration
  • Calculator runs calculations in browser, not sending data to server
  • UX includes accessibility features and clear financial limitations

More from Wednesday 2 September →