core: switch JSON library from jsoncpp to nlohmann/json#2918
Merged
Conversation
5d374eb to
ae8885b
Compare
Replace the compiled jsoncpp dependency with the header-only nlohmann/json (v3.11.3, already present transitively via libevents). - Parse paths use the non-throwing json::parse(..., allow_exceptions=false) with predicate-guarded access to stay abort-free under -fno-exceptions. - Rework the MavlinkDirect serializer (libmav_receiver) onto nlohmann::ordered_json + dump(), which fixes a latent string-escaping bug and renders NaN/Inf as null, while preserving field order. - Migrate mission import and component metadata (parse and serialize) and the system tests accordingly. - Update build wiring, packaging (.pc, CMake config, debian), CI, docs, and the mavlink_direct_sender example.
ae8885b to
4ad13c3
Compare
PARAM_EXT_{VALUE,SET,ACK}.param_value is declared as char[128] in the
MAVLink definition but the extended-parameter protocol uses it to carry
the raw bytes of a typed value. libmav treats char[] as a NUL-terminated
string (getString/strnlen), so any value containing a zero byte is
truncated on receive, and the bytes are usually not valid UTF-8.
Represent these fields (via an explicit, documented allow-list) as JSON
byte arrays, read as raw bytes so nothing is truncated. The field stays
declared char, so the message CRC_EXTRA is unchanged and wire
compatibility is preserved. The parse direction already accepts a number
array for char[] fields, so this round-trips.
Add a system test covering the round-trip (including an interior NUL) and
adapt the param-change-notification collector, which previously read
param_value as a string.
JonasVautherin
previously approved these changes
Jul 13, 2026
JonasVautherin
left a comment
Collaborator
There was a problem hiding this comment.
Just a small nitpick, feel free to ignore 🙈
…d lookup The binary char[] allow-list used a function-local static std::set<std::pair<std::string, std::string>>. Such a static has a runtime destructor that runs at process exit on the main thread, while a lingering io-context thread may still be serializing a message and calling find() on it -- the MAVLink fuzzer caught this as a heap-use-after-free. Replace the set with a constexpr std::array of std::string_view literals: no static object with a destructor, and no per-lookup heap allocation of a temporary pair. Behaviour is unchanged.
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Replace the compiled jsoncpp dependency with the header-only nlohmann/json (v3.11.3, already present transitively via
libevents).Why
ExternalProjectto build and link.std::ostringstreamconcatenation.dump()escapes correctly and rendersNaN/Infasnull.How
-fno-exceptions): parse via the non-throwingjson::parse(..., allow_exceptions=false)+is_discarded(), with predicate-guarded access so nlohmann never hits itsabort()path.libmav_receiver): reworked ontonlohmann::ordered_json+dump(), preserving field order (plainjsonwould sort keys).libmav_conversions,mission_import,mavlink_component_metadata,component_metadata_server_impl, and the system tests.third_party/nlohmann_json, removedjsoncpp+Findjsoncpp.cmake), packaging (.pc, CMake config,debian/control— header-only, so runtime dep dropped), CI, docs, and the example.Testing
build-debugandbuild-server-debugboth build cleanly..planfixtures + component metadata).