Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changes/unreleased/added-20261118-json-optional-helpers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Added
body: |-
Add json_helpers::opt_bool and json_helpers::opt_string for explicitly present scalar fields. They preserve None versus Some(default), and require serde(default) when a missing field must remain unset. Runtime, well-known-type, descriptor and generator crates that use the new helpers must ship together with internal dependency minimums raised to that release; these helpers are unavailable in older runtimes.
time: 2026-11-18T00:00:00Z
3 changes: 3 additions & 0 deletions .changes/unreleased/fixed-20261117-enum-128-bit-integers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: 'Enum deserialization through serde formats that deliver 128-bit integers, including value-based JSON with serde_json/arbitrary_precision, no longer echoes the number in errors. A number beyond the 64-bit range reports that it is out of range, and an in-range number takes the same path as a 64-bit one instead of being rejected as an invalid type. This covers generated enum values, enum fields, and reflective enum values.'
time: 2026-11-17T12:00:00Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: "Omit invalid FieldMask paths from serialization errors, consistently for owned, borrowed and reflective messages."
time: 2026-11-18T22:00:00+01:00
3 changes: 3 additions & 0 deletions .changes/unreleased/security-20261114-002418.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Security
body: 'Enum JSON value errors omit the input name or number. This covers generated enum values, enum field values and elements, registered enum extensions, and reflective enum values. Malformed scalar input at enum list and map boundaries is also omitted; the shared reflective collection visitors apply the same rule to other list and map fields. Accepted JSON values and lenient parsing behavior are unchanged. Regenerate existing bindings with the matching generator to update standalone enum deserialization.'
time: 2026-11-14T00:24:18Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Security
body: |-
Omit rejected values from ProtoJSON decoding diagnostics for map-key parsing, numeric conversion and range checks, base64 decoding, malformed Timestamp and Duration strings, and Any payload decoding. Registered Any decoder errors are reported as fixed diagnostics. Accepted inputs are unchanged. This covers Buffa diagnostics at those conversions and the Any decode boundary. Unknown-field diagnostics outside Any (including Serde-derived errors), parser and deserializer errors at other boundaries, and serialization errors are outside this change.
time: 2026-11-14T00:00:00Z
6 changes: 6 additions & 0 deletions .changes/unreleased/security-20261117-120000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Security
body: |-
Omit wrong-kind values from ProtoJSON decoding diagnostics at bool and string fields, including optional, repeated, map and oneof positions; scalar, bytes and container helpers; generated messages with a oneof or extension range; scalar and structural well-known types; and corresponding reflective JSON positions. Wide integer callbacks use checked narrowing and fixed rejection reasons. Default string representations use the redacting helpers. Custom string representations retain their native Serde conversions and validation in optional, repeated, map and oneof positions. Custom collection representations also retain the bool/default-string Serde paths they used before this hardening. JSON null remains unset/default where the protobuf mapping requires it, and null elements or map values remain rejected. Regenerate existing bindings with the matching generator to update generated routing.
Non-human-readable formats retain the typed map, sequence and string entry points they previously supported. New optional bool/default-string helpers retain native Option encoding there; this does not add a general binary-Serde compatibility guarantee to ProtoJSON types. With buffa-yaml, default string and temporal-string positions now follow JSON kinds: numeric and boolean YAML scalars are rejected instead of coerced into text in the newly routed positions. An empty repeated-string item is null and rejected. Custom string Serde policies are unchanged. Empty or comment-only YAML input still decodes as default message, Struct, ListValue or Empty values in typed and reflective codecs, and tags remain transparent at structural and temporal-string positions that previously ignored them. Bool/default-string scalar helpers reject tagged values, including tagged null, so a tag cannot bypass field presence or container null rejection. An explicitly empty YAML document (`---`) is now rejected at those structural positions: Serde reports it as the same unit kind as JSON null, which must remain invalid there.
Messages and Empty reject an unrecognized object member named $serde_json::private::Number, the spelling used by serde_json's unsupported arbitrary_precision feature to present some numbers as objects. An explicit schema json_name with that spelling remains valid. Such a message retains typed object checking so a synthetic number cannot be accepted as a field; its early wrong-kind errors remain Serde/parser diagnostics and can include input. Other remaining scope limits are derived messages without a oneof or extension range given a non-object, containers of those message types, Any given a non-object, parser errors and custom representation diagnostics. Struct and ordinary map keys continue to treat Serde's private token spellings as data.
time: 2026-11-17T12:00:00Z
4 changes: 4 additions & 0 deletions .changes/unreleased/security-20261117-120100.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Security
body: |-
Omit the rejected path from `FieldMask` JSON decoding diagnostics. A malformed path is now reported as `invalid FieldMask path, expected comma-separated lowerCamelCase paths`, by both the generated `FieldMask` and `DynamicMessage`'s JSON codec, instead of quoting the path and naming the rule it broke. Accepted paths are unchanged.
time: 2026-11-17T12:01:00Z
4 changes: 4 additions & 0 deletions .changes/unreleased/security-20261118-enum-map-keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Security
body: |-
Enum-valued maps now redact rejected primitive, string, newtype and unit-enum key conversions with invalid protobuf map key. Native key parsing, borrowed keys, enum filtering, syntax errors and reader errors are preserved. Conversion context is discarded without formatting it. Ignoring unknown fields in typed or reflective Empty no longer copies each key into an input-sized allocation.
time: 2026-11-18T00:01:00Z
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
- name: Tests
run: cargo test --workspace

- name: Enum diagnostics with arbitrary precision
run: cargo test -p buffa-test --features serde_json/arbitrary_precision --test enum_json_precision -- --ignored

# Optional features must keep compiling — #88 was a feature-flag-only
# break that escaped the default-features test pass above. cargo check
# is sufficient to catch compile breaks without doubling the test time.
Expand Down Expand Up @@ -100,6 +103,9 @@ jobs:
- name: Feature-gating compile matrix
run: cargo test -p buffa-codegen --test feature_gating_compile -- --ignored

- name: JSON diagnostic consumer compatibility
run: cargo test -p buffa-codegen --test json_diagnostics_compile -- --ignored

# Shared-pool mode emits each package's descriptor_pool() as a relative
# `super::…::__buffa_fds` path, so the hop count has to match the module
# nesting exactly. Only a real compiled tree proves it resolves; the
Expand Down
49 changes: 1 addition & 48 deletions buffa-codegen/src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,7 @@ fn generate_enum_serde(name_ident: &Ident) -> TokenStream {

impl<'de> ::serde::Deserialize<'de> for #name_ident {
fn deserialize<__D: ::serde::Deserializer<'de>>(d: __D) -> ::core::result::Result<Self, __D::Error> {
struct _V;
impl ::serde::de::Visitor<'_> for _V {
type Value = #name_ident;

fn expecting(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(concat!("a string, integer, or null for ", stringify!(#name_ident)))
}

fn visit_str<__E: ::serde::de::Error>(self, v: &str) -> ::core::result::Result<#name_ident, __E> {
<#name_ident as ::buffa::Enumeration>::from_proto_name(v).ok_or_else(|| {
::serde::de::Error::invalid_value(
::serde::de::Unexpected::Str(v),
&"a known enum variant name",
)
})
}

fn visit_i64<__E: ::serde::de::Error>(self, v: i64) -> ::core::result::Result<#name_ident, __E> {
let v32 = i32::try_from(v).map_err(|_| {
::serde::de::Error::custom(
::buffa::alloc::format!("enum value {v} out of i32 range")
)
})?;
<#name_ident as ::buffa::Enumeration>::from_i32(v32).ok_or_else(|| {
::serde::de::Error::custom(
::buffa::alloc::format!("unknown enum value {v32}")
)
})
}

fn visit_u64<__E: ::serde::de::Error>(self, v: u64) -> ::core::result::Result<#name_ident, __E> {
let v32 = i32::try_from(v).map_err(|_| {
::serde::de::Error::custom(
::buffa::alloc::format!("enum value {v} out of i32 range")
)
})?;
<#name_ident as ::buffa::Enumeration>::from_i32(v32).ok_or_else(|| {
::serde::de::Error::custom(
::buffa::alloc::format!("unknown enum value {v32}")
)
})
}

fn visit_unit<__E: ::serde::de::Error>(self) -> ::core::result::Result<#name_ident, __E> {
::core::result::Result::Ok(::core::default::Default::default())
}
}
d.deserialize_any(_V)
::buffa::json_helpers::closed_enum::deserialize_strict(d)
}
}

Expand Down
Loading
Loading