diff --git a/.github/workflows/crates-package-preflight.yml b/.github/workflows/crates-package-preflight.yml index b54113e2..1caf7c9c 100644 --- a/.github/workflows/crates-package-preflight.yml +++ b/.github/workflows/crates-package-preflight.yml @@ -13,7 +13,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Full commit SHA on main used for this release required: true diff --git a/.github/workflows/crates-release.yml b/.github/workflows/crates-release.yml index 32ffa552..fa75f8aa 100644 --- a/.github/workflows/crates-release.yml +++ b/.github/workflows/crates-release.yml @@ -11,7 +11,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Copy the full source SHA from the successful Crates Package Preflight summary required: true diff --git a/.github/workflows/kotlin-android-package-preflight.yml b/.github/workflows/kotlin-android-package-preflight.yml index 217cd183..38e1eab4 100644 --- a/.github/workflows/kotlin-android-package-preflight.yml +++ b/.github/workflows/kotlin-android-package-preflight.yml @@ -13,7 +13,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Full commit SHA on main used for this release required: true diff --git a/.github/workflows/kotlin-android-package-release.yml b/.github/workflows/kotlin-android-package-release.yml index 3341516c..278cb710 100644 --- a/.github/workflows/kotlin-android-package-release.yml +++ b/.github/workflows/kotlin-android-package-release.yml @@ -11,7 +11,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Copy the full source SHA from the successful Kotlin Android Package Preflight summary required: true diff --git a/.github/workflows/npm-package-preflight.yml b/.github/workflows/npm-package-preflight.yml index c2f4840f..433986eb 100644 --- a/.github/workflows/npm-package-preflight.yml +++ b/.github/workflows/npm-package-preflight.yml @@ -13,7 +13,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Full commit SHA on main used for this release required: true diff --git a/.github/workflows/npm-package-release.yml b/.github/workflows/npm-package-release.yml index 08ed6ccc..aff2f3ae 100644 --- a/.github/workflows/npm-package-release.yml +++ b/.github/workflows/npm-package-release.yml @@ -11,7 +11,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Copy the full source SHA from the successful npm Package Preflight summary required: true diff --git a/.github/workflows/swift-package-preflight.yml b/.github/workflows/swift-package-preflight.yml index 85b8add5..f101452c 100644 --- a/.github/workflows/swift-package-preflight.yml +++ b/.github/workflows/swift-package-preflight.yml @@ -13,7 +13,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Full commit SHA on main used for this release required: true diff --git a/.github/workflows/swift-package-release.yml b/.github/workflows/swift-package-release.yml index 9166e003..c294bfb2 100644 --- a/.github/workflows/swift-package-release.yml +++ b/.github/workflows/swift-package-release.yml @@ -11,7 +11,7 @@ on: description: Release version without leading v required: true type: string - default: 0.4.4 + default: 0.4.5 source_sha: description: Copy the full source SHA from the successful Swift Package Preflight summary required: true diff --git a/CHANGELOG.md b/CHANGELOG.md index e2187293..84172bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## 0.4.4 (unreleased) +## 0.4.5 (unreleased) + +- Allow explicit general-CBOR input, output, and aggregate byte-string budgets + up to 2 MiB. Defaults remain 1 MiB; other resource limits are unchanged. +- Apply the selected input budget to received fragments in both encoding adapters. + +## 0.4.4 - Require Rust 1.100 and ReallyMe Buffa 0.1.3. - Bound memory use when decoding nested or repeated DER SET OF values. diff --git a/Cargo.lock b/Cargo.lock index 92cf3087..8da89132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -638,7 +638,7 @@ dependencies = [ [[package]] name = "reallyme-codec" -version = "0.4.4" +version = "0.4.5" dependencies = [ "der", "proptest", @@ -662,7 +662,7 @@ dependencies = [ [[package]] name = "reallyme-codec-adapter" -version = "0.4.4" +version = "0.4.5" dependencies = [ "reallyme-codec", "reallyme-codec-multibase", @@ -670,7 +670,7 @@ dependencies = [ [[package]] name = "reallyme-codec-base64" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-codec-proto", @@ -680,7 +680,7 @@ dependencies = [ [[package]] name = "reallyme-codec-base64url" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "serde", @@ -691,7 +691,7 @@ dependencies = [ [[package]] name = "reallyme-codec-cbor" -version = "0.4.4" +version = "0.4.5" dependencies = [ "cid", "half", @@ -708,7 +708,7 @@ dependencies = [ [[package]] name = "reallyme-codec-ffi" -version = "0.4.4" +version = "0.4.5" dependencies = [ "jni", "reallyme-buffa", @@ -720,7 +720,7 @@ dependencies = [ [[package]] name = "reallyme-codec-hex" -version = "0.4.4" +version = "0.4.5" dependencies = [ "thiserror", "zeroize", @@ -728,7 +728,7 @@ dependencies = [ [[package]] name = "reallyme-codec-jcs" -version = "0.4.4" +version = "0.4.5" dependencies = [ "itoa", "ryu-js", @@ -741,7 +741,7 @@ dependencies = [ [[package]] name = "reallyme-codec-multibase" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "bs58", @@ -752,14 +752,14 @@ dependencies = [ [[package]] name = "reallyme-codec-multicodec" -version = "0.4.4" +version = "0.4.5" dependencies = [ "thiserror", ] [[package]] name = "reallyme-codec-multikey" -version = "0.4.4" +version = "0.4.5" dependencies = [ "reallyme-codec-base64url", "reallyme-codec-multibase", @@ -770,7 +770,7 @@ dependencies = [ [[package]] name = "reallyme-codec-pem" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "pem", @@ -782,7 +782,7 @@ dependencies = [ [[package]] name = "reallyme-codec-proto" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-buffa", @@ -795,7 +795,7 @@ dependencies = [ [[package]] name = "reallyme-codec-wasm" -version = "0.4.4" +version = "0.4.5" dependencies = [ "js-sys", "reallyme-codec", diff --git a/Package.swift b/Package.swift index dd120b31..f006096e 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ // SwiftPM and Xcode only read `Package.swift` at the repository root when a // package is consumed by URL, e.g. // -// .package(url: "https://github.com/reallyme/codec", from: "0.4.4") +// .package(url: "https://github.com/reallyme/codec", from: "0.4.5") // .product(name: "ReallyMeCodec", package: "codec") // // The Swift sources live under `packages/swift/` to keep symmetry with the @@ -22,9 +22,9 @@ let ffiArtifactChecksumPlaceholder = "0000000000000000000000000000000000000000000000000000000000000000" // Keep the binary dependency disabled until preflight binds the matching archive. let ffiArtifactChecksum = "0000000000000000000000000000000000000000000000000000000000000000" -let ffiArtifactVersion = "0.4.4" +let ffiArtifactVersion = "0.4.5" let ffiArtifactLocalPathOverride = "" -let packageVersion = "0.4.4" +let packageVersion = "0.4.5" let hasReleasedFfiArtifact = ffiArtifactChecksum != ffiArtifactChecksumPlaceholder && ffiArtifactVersion == packageVersion let useRuntimeFfiProvider = diff --git a/README.md b/README.md index b167b61e..85638f66 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ strict DER reader or the borrowed `tlv` framing surface separately and select only the families they use: ```toml -reallyme-codec = { version = "0.4.4", default-features = false, features = [ +reallyme-codec = { version = "0.4.5", default-features = false, features = [ "base64url", "multikey", ] } @@ -117,7 +117,7 @@ Swift 6.3 or newer is required. ```swift .package( url: "https://github.com/reallyme/codec", - from: "0.4.4" + from: "0.4.5" ) ``` @@ -129,7 +129,7 @@ Swift 6.3 or newer is required. ```kotlin dependencies { - implementation("me.really:codec:0.4.4") + implementation("me.really:codec:0.4.5") } ``` @@ -137,7 +137,7 @@ dependencies { ```kotlin dependencies { - implementation("me.really:codec-android:0.4.4") + implementation("me.really:codec-android:0.4.5") } ``` @@ -161,7 +161,7 @@ compatible fixes increment the patch version, such as `0.4.0` to `0.4.1`. For Rust consumers, pin to the minor line you have reviewed, for example `reallyme-codec = "0.4"`. A full version written by `cargo add`, such as -`reallyme-codec = "0.4.4"`, uses Cargo caret semantics and remains on the same +`reallyme-codec = "0.4.5"`, uses Cargo caret semantics and remains on the same `0.4.x` compatibility line. For npm, Maven, SwiftPM, and release artifacts used in production, prefer exact versions or locked dependency files so every language lane runs the same reviewed codec release. diff --git a/crates/adapter/Cargo.toml b/crates/adapter/Cargo.toml index e0dcd9bf..042f567d 100644 --- a/crates/adapter/Cargo.toml +++ b/crates/adapter/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-adapter" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -13,10 +13,10 @@ publish.workspace = true description = "Internal scalar policy for ReallyMe codec boundaries." [dependencies] -codec-runtime = { package = "reallyme-codec", version = "=0.4.4", path = "../codec", default-features = false, features = ["operation-contract"] } +codec-runtime = { package = "reallyme-codec", version = "=0.4.5", path = "../codec", default-features = false, features = ["operation-contract"] } [dev-dependencies] -codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.4", path = "../multibase" } +codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.5", path = "../multibase" } [lints] workspace = true diff --git a/crates/base64/Cargo.toml b/crates/base64/Cargo.toml index e61ece0d..051304c3 100644 --- a/crates/base64/Cargo.toml +++ b/crates/base64/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-base64" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -17,7 +17,7 @@ include = ["/src/**/*.rs", "/tests/**/*.rs", "/Cargo.toml", "/LICENSE", "/NOTICE name = "codec_base64" [dependencies] -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", default-features = false, features = ["generated"] } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", default-features = false, features = ["generated"] } base64 = { workspace = true } thiserror = { workspace = true } zeroize = { workspace = true } diff --git a/crates/base64url/Cargo.toml b/crates/base64url/Cargo.toml index f2be621e..2d292793 100644 --- a/crates/base64url/Cargo.toml +++ b/crates/base64url/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-base64url" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/cbor/Cargo.toml b/crates/cbor/Cargo.toml index 33349d66..38f36efa 100644 --- a/crates/cbor/Cargo.toml +++ b/crates/cbor/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-cbor" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -18,7 +18,7 @@ name = "codec_cbor" [dependencies] buffa.workspace = true -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", features = ["generated"] } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", features = ["generated"] } half = { workspace = true } cid = { workspace = true } multihash = { workspace = true } diff --git a/crates/cbor/src/general/encode.rs b/crates/cbor/src/general/encode.rs index 53e521cc..6be010a6 100644 --- a/crates/cbor/src/general/encode.rs +++ b/crates/cbor/src/general/encode.rs @@ -158,6 +158,9 @@ impl Encoder { // Account the original structure, not a second semantic tree. Final // profile validation rejects incompatible widths rather than silently // rebuilding bytes that may already be authenticated. + if frame.received_bytes().len() > self.budget.limits.input { + return Err(error(ErrorReason::InputLimit)); + } scan( frame.received_bytes(), &mut self.budget, @@ -217,13 +220,12 @@ impl Encoder { let value = node.value.as_ref().ok_or(error(ErrorReason::WrongType))?; self.budget.charge(1)?; if let Value::ReceivedValue(value) = value { - // Native Received holds a Frame, which proves exact framing and - // the hard input ceiling. Re-establish that proof for wire bytes - // before they can be embedded in a constructed container. + // The caller-selected input budget applies to received fragments + // in both native and generated inputs, independently of output. if value.value.is_empty() { return Err(error(ErrorReason::EmptyInput)); } - if value.value.len() > super::limits::MAX_BYTES { + if value.value.len() > self.budget.limits.input { return Err(error(ErrorReason::InputLimit)); } let received = scan( diff --git a/crates/cbor/src/general/limits.rs b/crates/cbor/src/general/limits.rs index 9ca878fe..27d4d81a 100644 --- a/crates/cbor/src/general/limits.rs +++ b/crates/cbor/src/general/limits.rs @@ -5,8 +5,12 @@ use super::error::{error, CborError, ErrorReason}; use super::profile::Profile; -/// Hard cap for one received input or protected output: one MiB. -pub const MAX_BYTES: usize = 1_048_576; +/// Default received input, protected output, and aggregate byte-string budget: one MiB. +pub const DEFAULT_BYTES: usize = 1_048_576; +/// Explicit ceiling for received input, protected output, and aggregate byte strings: two MiB. +pub const MAX_BYTES: usize = 2_097_152; +/// Default and ceiling for aggregate UTF-8 text; raising binary budgets does not raise this. +pub const MAX_TEXT_BYTES: usize = 1_048_576; /// Hard cap for simultaneously open containers and tags. pub const MAX_DEPTH: usize = 64; /// Hard cap for structural nodes, including tags and string chunks. @@ -25,6 +29,9 @@ const ENCODED_KEY_MAX_COMPARISON_BYTES: usize = 1_048_576; /// Caller-configurable limits; private fields prevent bypassing hard ceilings. /// /// Container entries default to 4,096 and may be explicitly raised to 65,536. +/// Input, output, and aggregate byte strings default independently to one MiB +/// and may each be explicitly raised to two MiB. Encoded byte budgets include +/// headers; aggregate content budgets do not. Text remains capped at one MiB. /// The independent node, byte, depth, and work budgets still apply to the whole /// operation, so a container and its children must fit within the node budget. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -105,7 +112,7 @@ impl Limits { with_text_bytes, text_bytes, text, - MAX_BYTES, + MAX_TEXT_BYTES, "Set or inspect aggregate UTF-8 text bytes." ); limit!( @@ -120,13 +127,13 @@ impl Limits { impl Default for Limits { fn default() -> Self { Self { - input: MAX_BYTES, - output: MAX_BYTES, + input: DEFAULT_BYTES, + output: DEFAULT_BYTES, depth: MAX_DEPTH, nodes: MAX_NODES, entries: DEFAULT_ENTRIES, - bytes: MAX_BYTES, - text: MAX_BYTES, + bytes: DEFAULT_BYTES, + text: MAX_TEXT_BYTES, work: DEFAULT_WORK, } } diff --git a/crates/cbor/src/general/mod.rs b/crates/cbor/src/general/mod.rs index 8913cacf..23008869 100644 --- a/crates/cbor/src/general/mod.rs +++ b/crates/cbor/src/general/mod.rs @@ -84,7 +84,10 @@ pub use cursor::Cursor; pub use encode::{encode, EncodedCbor, MapEntry, ValueRef}; pub use error::{CborError, ErrorReason}; pub use float::{Float, FloatWidth}; -pub use limits::{Limits, DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, MAX_WORK}; +pub use limits::{ + Limits, DEFAULT_BYTES, DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, + MAX_TEXT_BYTES, MAX_WORK, +}; pub use profile::{ FloatPolicy, LengthPolicy, MapKeyEquality, MapOrdering, NanPolicy, Profile, Serialization, }; diff --git a/crates/cbor/tests/general/resource_tests.rs b/crates/cbor/tests/general/resource_tests.rs index 34e9aab9..c9d2d9e3 100644 --- a/crates/cbor/tests/general/resource_tests.rs +++ b/crates/cbor/tests/general/resource_tests.rs @@ -7,8 +7,8 @@ use proptest::prelude::{any, proptest}; use super::{ bytes, encode, frame_exact, frame_prefix, read_header_prefix, reason, validate_exact, ArgumentWidth, ErrorReason, Float, FloatPolicy, LengthPolicy, Limits, MapEntry, MapOrdering, - Profile, Serialization, ValueRef, DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, - MAX_NODES, MAX_WORK, + Profile, Serialization, ValueRef, DEFAULT_BYTES, DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, + MAX_ENTRIES, MAX_NODES, MAX_TEXT_BYTES, MAX_WORK, }; #[test] @@ -20,7 +20,7 @@ fn all_resource_limits_enforce_their_hard_ceilings_and_tighter_budgets() { Limits::default().with_nodes(MAX_NODES + 1), Limits::default().with_entries(MAX_ENTRIES + 1), Limits::default().with_byte_string_bytes(MAX_BYTES + 1), - Limits::default().with_text_bytes(MAX_BYTES + 1), + Limits::default().with_text_bytes(MAX_TEXT_BYTES + 1), Limits::default().with_work(MAX_WORK + 1), ] { reason(limits, ErrorReason::InvalidLimit); @@ -150,9 +150,9 @@ fn maximum_input_depth_nodes_and_huge_declarations_are_bounded() { ErrorReason::InputLimit, ); let mut exact = vec![0x5a, 0x00, 0x0f, 0xff, 0xfb]; - exact.resize(MAX_BYTES, 0); + exact.resize(DEFAULT_BYTES, 0); let frame = frame_exact(&exact, Limits::default(), LengthPolicy::DefiniteOnly).unwrap(); - assert_eq!(frame.as_bytes().unwrap().len(), MAX_BYTES - 5); + assert_eq!(frame.as_bytes().unwrap().len(), DEFAULT_BYTES - 5); } #[test] diff --git a/crates/cbor/tests/general_byte_limit_tests.rs b/crates/cbor/tests/general_byte_limit_tests.rs new file mode 100644 index 00000000..fb21d298 --- /dev/null +++ b/crates/cbor/tests/general_byte_limit_tests.rs @@ -0,0 +1,355 @@ +// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Binary budgets are independent of defaults, framing overhead, and text policy. +#![allow( + missing_docs, + clippy::unwrap_used, + reason = "bounded byte-limit fixtures" +)] + +use codec_cbor::general::{ + encode, encode_value, frame_exact, frame_prefix, validate_exact, CborError, Cursor, + ErrorReason, LengthPolicy, Limits, Profile, ValueRef, DEFAULT_BYTES, MAX_BYTES, MAX_TEXT_BYTES, +}; +use codec_proto::generated::proto::reallyme::codec::v1 as proto; +use zeroize::{ZeroizeOnDrop, Zeroizing}; + +const LARGE_STRING_HEADER_BYTES: usize = 5; + +fn reason(result: Result, expected: ErrorReason) { + assert_eq!(result.err().map(CborError::reason), Some(expected)); +} + +fn limits(input: usize, output: usize, bytes: usize) -> Limits { + Limits::default() + .with_input_bytes(input) + .unwrap() + .with_output_bytes(output) + .unwrap() + .with_byte_string_bytes(bytes) + .unwrap() +} + +fn byte_string(payload: usize) -> Zeroizing> { + let mut encoded = Zeroizing::new(vec![0x5a]); + encoded.extend_from_slice(&u32::try_from(payload).unwrap().to_be_bytes()); + encoded.resize( + payload.checked_add(LARGE_STRING_HEADER_BYTES).unwrap(), + 0xa5, + ); + encoded +} + +#[test] +fn omitted_zero_exact_ceiling_and_unrepresentable_limits_keep_the_contract() { + let default = Limits::try_from(&proto::CodecGeneralCborOptions::default()).unwrap(); + assert_eq!(DEFAULT_BYTES, 1_048_576); + assert_eq!(MAX_BYTES, 2_097_152); + assert_eq!(default.input_bytes(), DEFAULT_BYTES); + assert_eq!(default.output_bytes(), DEFAULT_BYTES); + assert_eq!(default.byte_string_bytes(), DEFAULT_BYTES); + assert_eq!(default.text_bytes(), MAX_TEXT_BYTES); + for value in [0, 1, DEFAULT_BYTES, MAX_BYTES] { + let options = proto::CodecGeneralCborOptions { + input_bytes: Some(u64::try_from(value).unwrap()), + output_bytes: Some(u64::try_from(value).unwrap()), + byte_string_bytes: Some(u64::try_from(value).unwrap()), + ..Default::default() + }; + assert_eq!( + Limits::try_from(&options).unwrap(), + limits(value, value, value) + ); + } + for value in [MAX_BYTES.checked_add(1).unwrap(), usize::MAX] { + reason(default.with_input_bytes(value), ErrorReason::InvalidLimit); + reason(default.with_output_bytes(value), ErrorReason::InvalidLimit); + reason( + default.with_byte_string_bytes(value), + ErrorReason::InvalidLimit, + ); + } + for options in [ + proto::CodecGeneralCborOptions { + input_bytes: Some(u64::MAX), + ..Default::default() + }, + proto::CodecGeneralCborOptions { + output_bytes: Some(u64::MAX), + ..Default::default() + }, + proto::CodecGeneralCborOptions { + byte_string_bytes: Some(u64::MAX), + ..Default::default() + }, + ] { + reason(Limits::try_from(&options), ErrorReason::InvalidLimit); + } + reason( + default.with_text_bytes(MAX_TEXT_BYTES.checked_add(1).unwrap()), + ErrorReason::InvalidLimit, + ); + reason( + frame_exact(&[0x40], limits(0, 0, 0), LengthPolicy::DefiniteOnly), + ErrorReason::InputLimit, + ); + reason( + encode(&ValueRef::Bytes(&[]), Profile::preferred(), limits(1, 0, 0)), + ErrorReason::OutputLimit, + ); + validate_exact(&[0x40], Profile::preferred(), limits(1, 1, 0)).unwrap(); +} + +#[test] +fn exact_encoded_budgets_count_headers_and_default_admission_stays_one_mib() { + fn protected() {} + protected::(); + for selected in [ + DEFAULT_BYTES, + DEFAULT_BYTES.checked_add(1).unwrap(), + MAX_BYTES, + ] { + let payload = selected.checked_sub(LARGE_STRING_HEADER_BYTES).unwrap(); + let expected = byte_string(payload); + let selected_limits = limits(selected, selected, payload); + let encoded = encode( + &ValueRef::Bytes(&expected[LARGE_STRING_HEADER_BYTES..]), + Profile::preferred(), + selected_limits, + ) + .unwrap(); + assert_eq!(encoded.as_bytes(), expected.as_slice()); + let item = validate_exact(&expected, Profile::preferred(), selected_limits).unwrap(); + assert_eq!(item.frame().received_bytes().as_ptr(), expected.as_ptr()); + assert_eq!(item.frame().as_bytes().unwrap().len(), payload); + frame_exact(&expected, selected_limits, LengthPolicy::DefiniteOnly).unwrap(); + reason( + validate_exact( + &expected, + Profile::preferred(), + selected_limits + .with_input_bytes(selected.checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::InputLimit, + ); + reason( + encode( + &ValueRef::Bytes(&expected[LARGE_STRING_HEADER_BYTES..]), + Profile::preferred(), + selected_limits + .with_output_bytes(selected.checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::OutputLimit, + ); + reason( + validate_exact( + &expected, + Profile::preferred(), + selected_limits + .with_byte_string_bytes(payload.checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::ByteStringLimit, + ); + reason( + encode( + &ValueRef::Bytes(&expected[LARGE_STRING_HEADER_BYTES..]), + Profile::preferred(), + selected_limits + .with_byte_string_bytes(payload.checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::ByteStringLimit, + ); + if selected > DEFAULT_BYTES { + reason( + frame_prefix(&expected, Limits::default(), LengthPolicy::DefiniteOnly), + ErrorReason::InputLimit, + ); + reason( + encode( + &ValueRef::Bytes(&expected[LARGE_STRING_HEADER_BYTES..]), + Profile::preferred(), + Limits::default().with_byte_string_bytes(MAX_BYTES).unwrap(), + ), + ErrorReason::OutputLimit, + ); + } + } + let over = byte_string( + MAX_BYTES + .checked_sub(LARGE_STRING_HEADER_BYTES) + .unwrap() + .checked_add(1) + .unwrap(), + ); + reason( + frame_exact( + &over, + limits(MAX_BYTES, MAX_BYTES, MAX_BYTES), + LengthPolicy::DefiniteOnly, + ), + ErrorReason::InputLimit, + ); +} + +#[test] +fn received_fragments_obey_selected_input_limits_in_both_encoder_adapters() { + let received = byte_string(DEFAULT_BYTES); + let raised = limits(MAX_BYTES, MAX_BYTES, MAX_BYTES); + let frame = frame_exact(&received, raised, LengthPolicy::DefiniteOnly).unwrap(); + let generated = proto::CodecGeneralCborValue::default().with_value( + proto::codec_general_cbor_value::Value::ReceivedValue(Box::new( + proto::CodecBytesResult::default().with_value(received.to_vec()), + )), + ); + for selected in [DEFAULT_BYTES, received.len()] { + let selected_limits = raised.with_input_bytes(selected).unwrap(); + let native = encode( + &ValueRef::Received(&frame), + Profile::preferred(), + selected_limits, + ); + let wire = encode_value(&generated, Profile::preferred(), selected_limits); + if selected == DEFAULT_BYTES { + reason(native, ErrorReason::InputLimit); + reason(wire, ErrorReason::InputLimit); + } else { + assert_eq!(native.unwrap().as_bytes(), received.as_slice()); + assert_eq!(wire.unwrap().as_bytes(), received.as_slice()); + } + } + // Constructed bytes have no received CBOR input; output remains independent. + encode( + &ValueRef::Bytes(&received[LARGE_STRING_HEADER_BYTES..]), + Profile::preferred(), + raised.with_input_bytes(0).unwrap(), + ) + .unwrap(); +} + +#[test] +fn aggregate_bytes_accumulate_across_containers_and_cursors() { + let payload = Zeroizing::new(vec![0xa5; DEFAULT_BYTES / 2]); + let values = [ValueRef::Bytes(&payload), ValueRef::Bytes(&payload)]; + let total = payload.len().checked_mul(2).unwrap(); + let raised = limits(MAX_BYTES, MAX_BYTES, total); + let encoded = encode(&ValueRef::Array(&values), Profile::preferred(), raised).unwrap(); + let item = validate_exact(encoded.as_bytes(), Profile::preferred(), raised).unwrap(); + assert_eq!(item.children().unwrap().count(), 2); + let lower = raised + .with_byte_string_bytes(total.checked_sub(1).unwrap()) + .unwrap(); + reason( + encode(&ValueRef::Array(&values), Profile::preferred(), lower), + ErrorReason::ByteStringLimit, + ); + reason( + validate_exact(encoded.as_bytes(), Profile::preferred(), lower), + ErrorReason::ByteStringLimit, + ); + let sequence = &encoded.as_bytes()[1..]; + let mut cursor = Cursor::new(sequence, lower, LengthPolicy::DefiniteOnly).unwrap(); + cursor.next().unwrap().unwrap(); + reason(cursor.next().unwrap(), ErrorReason::ByteStringLimit); + assert!(cursor.next().is_none()); + let mut cursor = Cursor::new(sequence, raised, LengthPolicy::DefiniteOnly).unwrap(); + assert_eq!(cursor.by_ref().map(Result::unwrap).count(), 2); + assert_eq!(cursor.consumed_bytes(), sequence); +} + +#[test] +fn embedded_and_outer_budgets_are_separate_and_received_bytes_are_unchanged() { + let inner = byte_string(DEFAULT_BYTES); + let mut outer = Zeroizing::new(vec![0xd8, 0x18, 0x5a]); + outer.extend_from_slice(&u32::try_from(inner.len()).unwrap().to_be_bytes()); + outer.extend_from_slice(&inner); + let raised = limits(MAX_BYTES, MAX_BYTES, MAX_BYTES); + let outer_item = validate_exact(&outer, Profile::preferred(), raised).unwrap(); + let tagged = outer_item.frame().tagged_bytes().unwrap(); + assert_eq!(tagged.received_bytes(), outer.as_slice()); + assert_eq!(tagged.payload_bytes(), inner.as_slice()); + reason( + tagged.validate_embedded(Profile::preferred(), Limits::default()), + ErrorReason::InputLimit, + ); + let embedded = tagged + .validate_embedded(Profile::preferred(), raised) + .unwrap(); + assert_eq!(embedded.frame().received_bytes(), inner.as_slice()); + reason( + validate_exact( + &outer, + Profile::preferred(), + raised + .with_byte_string_bytes(inner.len().checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::ByteStringLimit, + ); + reason( + tagged.validate_embedded( + Profile::preferred(), + raised + .with_byte_string_bytes(DEFAULT_BYTES.checked_sub(1).unwrap()) + .unwrap(), + ), + ErrorReason::ByteStringLimit, + ); +} + +#[test] +fn raised_binary_limits_do_not_weaken_text_or_structural_checks() { + let raised = limits(MAX_BYTES, MAX_BYTES, MAX_BYTES); + for (input, expected) in [ + (&[0x42, 0x01][..], ErrorReason::Truncated), + (&[0x61, 0xff][..], ErrorReason::InvalidUtf8), + (&[0x00, 0x00][..], ErrorReason::TrailingData), + ( + &[0xa2, 0x00, 0x01, 0x00, 0x02][..], + ErrorReason::DuplicateMapKey, + ), + ] { + reason( + validate_exact(input, Profile::preferred(), raised), + expected, + ); + } + let text = Zeroizing::new("a".repeat(MAX_TEXT_BYTES.checked_add(1).unwrap())); + reason( + encode(&ValueRef::Text(&text), Profile::preferred(), raised), + ErrorReason::TextLimit, + ); + reason( + validate_exact( + &[0x81, 0x00], + Profile::preferred(), + raised.with_nodes(1).unwrap(), + ), + ErrorReason::NodeLimit, + ); + reason( + validate_exact( + &[0x81, 0x00], + Profile::preferred(), + raised.with_entries(0).unwrap(), + ), + ErrorReason::EntryLimit, + ); + reason( + validate_exact( + &[0x81, 0x00], + Profile::preferred(), + raised.with_depth(0).unwrap(), + ), + ErrorReason::DepthLimit, + ); + reason( + validate_exact(&[0x00], Profile::preferred(), raised.with_work(0).unwrap()), + ErrorReason::WorkLimit, + ); +} diff --git a/crates/cbor/tests/general_entry_limit_tests.rs b/crates/cbor/tests/general_entry_limit_tests.rs index 95a94baa..50fbb1d2 100644 --- a/crates/cbor/tests/general_entry_limit_tests.rs +++ b/crates/cbor/tests/general_entry_limit_tests.rs @@ -7,7 +7,7 @@ use codec_cbor::general::{ encode, encode_value, validate_exact, CborError, ErrorReason, Limits, Profile, ValueRef, - DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, MAX_WORK, + DEFAULT_BYTES, DEFAULT_ENTRIES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, MAX_TEXT_BYTES, MAX_WORK, }; use codec_proto::generated::proto::reallyme::codec::v1 as proto; @@ -59,12 +59,12 @@ fn defaults_and_all_other_limit_fields_remain_unchanged() { assert_eq!(DEFAULT_ENTRIES, 4_096); assert_eq!(MAX_ENTRIES, 65_536); assert_eq!(defaults.entries(), DEFAULT_ENTRIES); - assert_eq!(defaults.input_bytes(), MAX_BYTES); - assert_eq!(defaults.output_bytes(), MAX_BYTES); + assert_eq!(defaults.input_bytes(), DEFAULT_BYTES); + assert_eq!(defaults.output_bytes(), DEFAULT_BYTES); assert_eq!(defaults.depth(), MAX_DEPTH); assert_eq!(defaults.nodes(), MAX_NODES); - assert_eq!(defaults.byte_string_bytes(), MAX_BYTES); - assert_eq!(defaults.text_bytes(), MAX_BYTES); + assert_eq!(defaults.byte_string_bytes(), DEFAULT_BYTES); + assert_eq!(defaults.text_bytes(), MAX_TEXT_BYTES); assert_eq!(defaults.work(), 16_777_216); assert_eq!(MAX_WORK, 67_108_864); diff --git a/crates/cbor/tests/general_tests.rs b/crates/cbor/tests/general_tests.rs index 8b7a11c1..232c98e6 100644 --- a/crates/cbor/tests/general_tests.rs +++ b/crates/cbor/tests/general_tests.rs @@ -7,8 +7,8 @@ use codec_cbor::general::{ encode, frame_exact, frame_prefix, read_header_prefix, validate_exact, validate_prefix, ArgumentWidth, CborError, Cursor, ErrorReason, Float, FloatPolicy, FloatWidth, LengthPolicy, - Limits, MajorType, MapEntry, MapOrdering, Profile, Serialization, ValueRef, DEFAULT_ENTRIES, - MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, MAX_WORK, + Limits, MajorType, MapEntry, MapOrdering, Profile, Serialization, ValueRef, DEFAULT_BYTES, + DEFAULT_ENTRIES, MAX_BYTES, MAX_DEPTH, MAX_ENTRIES, MAX_NODES, MAX_TEXT_BYTES, MAX_WORK, }; fn bytes(hex: &str) -> Vec { diff --git a/crates/cbor/tests/general_zeroization_tests.rs b/crates/cbor/tests/general_zeroization_tests.rs index ab01277a..8e0ed44b 100644 --- a/crates/cbor/tests/general_zeroization_tests.rs +++ b/crates/cbor/tests/general_zeroization_tests.rs @@ -6,6 +6,8 @@ //! One test prevents concurrent allocator-observation cases within this binary. #![allow(missing_docs, unsafe_code, clippy::unwrap_used)] +#[cfg(not(miri))] +use codec_cbor::general::MAX_BYTES; use codec_cbor::general::{ encode, frame_exact, ErrorReason, Float, LengthPolicy, Limits, MapEntry, Profile, ValueRef, }; @@ -129,6 +131,39 @@ fn initialized_output_is_wiped_on_success_and_semantic_rejection() { assert_eq!(error.reason(), ErrorReason::DuplicateMapKey); assert!(WATCH_POINTER.load(Ordering::SeqCst).is_null()); assert!(WIPED.load(Ordering::SeqCst)); + + // Cap-sized buffers run in the compiled test and sanitizer lanes. Miri + // keeps the success, partial-output, and semantic-rejection cases above; + // interpreting millions of volatile wipes adds cost without another path. + #[cfg(not(miri))] + { + let payload = zeroize::Zeroizing::new(vec![0xab; MAX_BYTES.checked_sub(5).unwrap()]); + let limits = Limits::default() + .with_output_bytes(MAX_BYTES) + .unwrap() + .with_byte_string_bytes(MAX_BYTES) + .unwrap(); + WATCH_SIZE.store(MAX_BYTES, Ordering::SeqCst); + WIPED.store(false, Ordering::SeqCst); + let output = encode(&ValueRef::Bytes(&payload), Profile::preferred(), limits).unwrap(); + assert!(!WATCH_POINTER.load(Ordering::SeqCst).is_null()); + drop(output); + assert!(WIPED.load(Ordering::SeqCst)); + + // This budget admits measurement and the second-pass header, then fails + // while appending contents. The full two-MiB output allocation must clear. + WIPED.store(false, Ordering::SeqCst); + let error = encode( + &ValueRef::Bytes(&payload), + Profile::preferred(), + limits.with_work(MAX_BYTES.checked_add(8).unwrap()).unwrap(), + ) + .err() + .unwrap(); + assert_eq!(error.reason(), ErrorReason::WorkLimit); + assert!(WATCH_POINTER.load(Ordering::SeqCst).is_null()); + assert!(WIPED.load(Ordering::SeqCst)); + } WATCH_SIZE.store(0, Ordering::SeqCst); OBSERVE.with(|observe| observe.set(false)); } diff --git a/crates/codec/Cargo.toml b/crates/codec/Cargo.toml index 0082f72b..433a9433 100644 --- a/crates/codec/Cargo.toml +++ b/crates/codec/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -15,16 +15,16 @@ readme = "README.md" include = ["/src/**/*.rs", "/Cargo.toml", "/README.md", "/LICENSE", "/NOTICE"] [dependencies] -codec-base64 = { package = "reallyme-codec-base64", version = "=0.4.4", path = "../base64", optional = true } -codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.4", path = "../base64url", optional = true } -codec-cbor = { package = "reallyme-codec-cbor", version = "=0.4.4", path = "../cbor", optional = true } -codec-hex = { package = "reallyme-codec-hex", version = "=0.4.4", path = "../hex", optional = true } -codec-jcs = { package = "reallyme-codec-jcs", version = "=0.4.4", path = "../jcs", optional = true } -codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.4", path = "../multibase", optional = true } -codec-multicodec = { package = "reallyme-codec-multicodec", version = "=0.4.4", path = "../multicodec", optional = true } -codec-multikey = { package = "reallyme-codec-multikey", version = "=0.4.4", path = "../multikey", optional = true } -codec-pem = { package = "reallyme-codec-pem", version = "=0.4.4", path = "../pem", optional = true } -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", default-features = false, features = ["generated"], optional = true } +codec-base64 = { package = "reallyme-codec-base64", version = "=0.4.5", path = "../base64", optional = true } +codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.5", path = "../base64url", optional = true } +codec-cbor = { package = "reallyme-codec-cbor", version = "=0.4.5", path = "../cbor", optional = true } +codec-hex = { package = "reallyme-codec-hex", version = "=0.4.5", path = "../hex", optional = true } +codec-jcs = { package = "reallyme-codec-jcs", version = "=0.4.5", path = "../jcs", optional = true } +codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.5", path = "../multibase", optional = true } +codec-multicodec = { package = "reallyme-codec-multicodec", version = "=0.4.5", path = "../multicodec", optional = true } +codec-multikey = { package = "reallyme-codec-multikey", version = "=0.4.5", path = "../multikey", optional = true } +codec-pem = { package = "reallyme-codec-pem", version = "=0.4.5", path = "../pem", optional = true } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", default-features = false, features = ["generated"], optional = true } buffa = { workspace = true, optional = true } der-core = { workspace = true, optional = true } thiserror = { workspace = true, optional = true } diff --git a/crates/codec/README.md b/crates/codec/README.md index 5e498f2c..3080d5ad 100644 --- a/crates/codec/README.md +++ b/crates/codec/README.md @@ -5,7 +5,7 @@ PEM, DER and definite TLV framing. ```toml [dependencies] -reallyme-codec = "0.4.4" +reallyme-codec = "0.4.5" ``` ```rust diff --git a/crates/codec/tests/expanded_contract_tests.rs b/crates/codec/tests/expanded_contract_tests.rs index 36c2e385..a3a76ff1 100644 --- a/crates/codec/tests/expanded_contract_tests.rs +++ b/crates/codec/tests/expanded_contract_tests.rs @@ -119,7 +119,7 @@ fn scalar_contract_matches_independent_literals() { result.package_minor, result.package_patch ), - (0, 4, 4) + (0, 4, 5) ); } diff --git a/crates/codec/tests/general_cbor_byte_limit_operations.rs b/crates/codec/tests/general_cbor_byte_limit_operations.rs new file mode 100644 index 00000000..2dfa2865 --- /dev/null +++ b/crates/codec/tests/general_cbor_byte_limit_operations.rs @@ -0,0 +1,296 @@ +// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Generated protobuf and ProtoJSON retain independent general-CBOR budgets. +#![cfg(feature = "operation-contract")] +#![allow( + missing_docs, + clippy::unwrap_used, + clippy::panic, + reason = "bounded operation fixtures" +)] + +use codec_proto::generated::proto::reallyme::codec::v1 as proto; +use codec_proto::{decode_protobuf, encode_protobuf}; +use proto::codec_api_operation_request::Operation; +use proto::codec_api_operation_result::Result as Output; +use proto::CodecGeneralCborErrorReason as Reason; +use reallyme_codec::cbor::general::{DEFAULT_BYTES, MAX_BYTES}; +use reallyme_codec::operation_contract::{ + process_operation_response, process_operation_response_json, +}; +use zeroize::Zeroizing; + +fn options() -> proto::CodecGeneralCborOptions { + proto::CodecGeneralCborOptions { + serialization: + proto::CodecGeneralCborSerialization::CODEC_GENERAL_CBOR_SERIALIZATION_RECEIVED.into(), + lengths: + proto::CodecGeneralCborLengthPolicy::CODEC_GENERAL_CBOR_LENGTH_POLICY_DEFINITE_ONLY + .into(), + floats: proto::CodecGeneralCborFloatPolicy::CODEC_GENERAL_CBOR_FLOAT_POLICY_ALL.into(), + ordering: proto::CodecGeneralCborMapOrdering::CODEC_GENERAL_CBOR_MAP_ORDERING_RECEIVED + .into(), + input_bytes: Some(u64::try_from(MAX_BYTES).unwrap()), + output_bytes: Some(u64::try_from(MAX_BYTES).unwrap()), + byte_string_bytes: Some(u64::try_from(MAX_BYTES).unwrap()), + ..Default::default() + } +} + +fn wire(total: usize) -> Zeroizing> { + let mut value = Zeroizing::new(vec![0x5a]); + value.extend_from_slice( + &u32::try_from(total.checked_sub(5).unwrap()) + .unwrap() + .to_be_bytes(), + ); + value.resize(total, 0xa5); + value +} + +fn source( + encoded: &[u8], + options: Option, +) -> Box { + Box::new(proto::CodecGeneralCborSourceRequest { + encoded: encoded.to_vec().into(), + options: options.into(), + }) +} + +fn execute(operation: Operation) -> proto::CodecApiOperationResponse { + let request = proto::CodecApiOperationRequest::default().with_operation(operation); + let binary = encode_protobuf(&request).unwrap(); + let mut json = Zeroizing::new(Vec::new()); + serde_json::to_writer(&mut *json, &request).unwrap(); + let binary_response = process_operation_response(&binary); + let json_response = process_operation_response_json(&json); + assert_eq!(binary_response, json_response); + decode_protobuf(&binary_response).unwrap() +} + +fn result(response: &proto::CodecApiOperationResponse) -> &Output { + let Some(proto::codec_api_operation_response::Outcome::Result(value)) = + response.outcome.as_ref() + else { + panic!("expected operation result"); + }; + value.result.as_ref().unwrap() +} + +fn reason(response: &proto::CodecApiOperationResponse, expected: Reason) { + let Some(proto::codec_api_operation_response::Outcome::Error(value)) = + response.outcome.as_ref() + else { + panic!("expected typed operation failure"); + }; + assert_eq!( + value.origin.as_known(), + Some(proto::CodecErrorOrigin::CODEC_ERROR_ORIGIN_CALLER) + ); + let Some(proto::codec_api_error::Error::GeneralCbor(value)) = value.error.as_ref() else { + panic!("expected general-CBOR error family"); + }; + assert_eq!(value.detail.as_known(), Some(expected)); +} + +#[test] +fn source_operations_preserve_large_selected_limits_and_exact_spans() { + let encoded = wire(MAX_BYTES); + for operation in [ + Operation::GeneralCborFrameExact(source(&encoded, Some(options()))), + Operation::GeneralCborFramePrefix(source(&encoded, Some(options()))), + Operation::GeneralCborValidateExact(source(&encoded, Some(options()))), + Operation::GeneralCborValidatePrefix(source(&encoded, Some(options()))), + ] { + let response = execute(operation); + let frame = match result(&response) { + Output::GeneralCborFrameExact(frame) + | Output::GeneralCborFramePrefix(frame) + | Output::GeneralCborValidateExact(frame) + | Output::GeneralCborValidatePrefix(frame) => frame, + _ => panic!("expected framing result"), + }; + assert_eq!(frame.received.as_option().unwrap().offset, 0); + assert_eq!( + frame.received.as_option().unwrap().length, + u64::try_from(encoded.len()).unwrap() + ); + assert_eq!( + frame.options.as_option().unwrap().input_bytes, + Some(u64::try_from(MAX_BYTES).unwrap()) + ); + } + let response = execute(Operation::GeneralCborReadHeader(source( + &encoded, + Some(options()), + ))); + assert!(matches!( + result(&response), + Output::GeneralCborReadHeader(_) + )); + let response = execute(Operation::GeneralCborValidateExact(source(&encoded, None))); + reason( + &response, + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_INPUT_LIMIT, + ); + let mut tighter = options(); + tighter.input_bytes = Some(u64::try_from(MAX_BYTES.checked_sub(1).unwrap()).unwrap()); + reason( + &execute(Operation::GeneralCborFrameExact(source( + &encoded, + Some(tighter), + ))), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_INPUT_LIMIT, + ); + let mut tighter = options(); + tighter.byte_string_bytes = Some(u64::try_from(encoded.len().checked_sub(6).unwrap()).unwrap()); + reason( + &execute(Operation::GeneralCborValidateExact(source( + &encoded, + Some(tighter), + ))), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_BYTE_STRING_LIMIT, + ); +} + +#[test] +fn encoding_defaults_output_budget_and_received_input_budget_are_independent() { + let encoded = wire(MAX_BYTES); + let value = || { + proto::CodecGeneralCborValue::default().with_value( + proto::codec_general_cbor_value::Value::BytesValue(Box::new( + proto::CodecBytesResult::default().with_value(encoded[5..].to_vec()), + )), + ) + }; + let request = |value, options: Option| { + Operation::GeneralCborEncode(Box::new(proto::CodecGeneralCborEncodeRequest { + value: Some(value).into(), + options: options.into(), + })) + }; + reason( + &execute(request(value(), None)), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_BYTE_STRING_LIMIT, + ); + let mut selected = options(); + selected.input_bytes = Some(0); + let response = execute(request(value(), Some(selected))); + let Output::GeneralCborEncode(bytes) = result(&response) else { + panic!("expected encoded bytes"); + }; + assert_eq!(bytes.value.as_slice(), encoded.as_slice()); + let mut selected = options(); + selected.output_bytes = Some(u64::try_from(MAX_BYTES.checked_sub(1).unwrap()).unwrap()); + reason( + &execute(request(value(), Some(selected))), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_OUTPUT_LIMIT, + ); + let received = proto::CodecGeneralCborValue::default().with_value( + proto::codec_general_cbor_value::Value::ReceivedValue(Box::new( + proto::CodecBytesResult::default().with_value(encoded.to_vec()), + )), + ); + let mut selected = options(); + selected.input_bytes = Some(u64::try_from(DEFAULT_BYTES).unwrap()); + reason( + &execute(request(received, Some(selected))), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_INPUT_LIMIT, + ); +} + +#[test] +fn cursor_children_and_embedded_operations_retain_the_selected_options() { + let mut encoded = Zeroizing::new(vec![0x81]); + encoded.extend_from_slice(&wire(DEFAULT_BYTES.checked_add(5).unwrap())); + let response = execute(Operation::GeneralCborCursor(source( + &encoded[1..], + Some(options()), + ))); + let Output::GeneralCborCursor(frames) = result(&response) else { + panic!("expected cursor"); + }; + assert_eq!(frames.values.len(), 1); + assert_eq!( + frames.options.as_option().unwrap().input_bytes, + options().input_bytes + ); + assert!(frames.values[0].options.as_option().is_none()); + let response = execute(Operation::GeneralCborInspect(Box::new( + proto::CodecGeneralCborInspectRequest { + encoded: encoded.to_vec().into(), + inspection: proto::CodecGeneralCborInspection::CODEC_GENERAL_CBOR_INSPECTION_CHILDREN + .into(), + validate: true, + options: Some(options()).into(), + }, + ))); + let Output::GeneralCborInspect(value) = result(&response) else { + panic!("expected inspection"); + }; + let Some(proto::codec_general_cbor_inspection_result::Value::Children(frames)) = + value.value.as_ref() + else { + panic!("expected child receipts"); + }; + assert_eq!(frames.values.len(), 1); + assert_eq!(frames.values[0].received.as_option().unwrap().offset, 1); + assert_eq!( + frames.options.as_option().unwrap().byte_string_bytes, + options().byte_string_bytes + ); + let mut outer = Zeroizing::new(vec![0xd8, 0x18, 0x5a]); + outer.extend_from_slice(&u32::try_from(encoded.len()).unwrap().to_be_bytes()); + outer.extend_from_slice(&encoded); + for (embedded, expected) in [(None, false), (Some(options()), true)] { + let response = execute(Operation::GeneralCborValidateEmbedded(Box::new( + proto::CodecGeneralCborEmbeddedRequest { + encoded: outer.to_vec().into(), + outer_options: Some(options()).into(), + embedded_options: embedded.into(), + }, + ))); + if expected { + let Output::GeneralCborValidateEmbedded(frame) = result(&response) else { + panic!("expected embedded receipt"); + }; + assert_eq!(frame.received.as_option().unwrap().offset, 7); + assert_eq!( + frame.received.as_option().unwrap().length, + u64::try_from(encoded.len()).unwrap() + ); + } else { + reason( + &response, + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_INPUT_LIMIT, + ); + } + } +} + +#[test] +fn generated_limits_above_the_ceiling_or_platform_size_are_typed_failures() { + for limit in [ + u64::try_from(MAX_BYTES).unwrap().checked_add(1).unwrap(), + u64::MAX, + ] { + for field in [0, 1, 2] { + let mut selected = options(); + match field { + 0 => selected.input_bytes = Some(limit), + 1 => selected.output_bytes = Some(limit), + _ => selected.byte_string_bytes = Some(limit), + } + reason( + &execute(Operation::GeneralCborFrameExact(source( + &[0], + Some(selected), + ))), + Reason::CODEC_GENERAL_CBOR_ERROR_REASON_INVALID_LIMIT, + ); + } + } +} diff --git a/crates/ffi/Cargo.toml b/crates/ffi/Cargo.toml index 49fad6d9..cd88bfa7 100644 --- a/crates/ffi/Cargo.toml +++ b/crates/ffi/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-ffi" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -20,9 +20,9 @@ default = ["jni"] jni = ["dep:jni"] [dependencies] -codec-adapter = { package = "reallyme-codec-adapter", version = "=0.4.4", path = "../adapter" } -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", features = ["generated"] } -codec-runtime = { package = "reallyme-codec", version = "=0.4.4", path = "../codec", default-features = false, features = ["operation-contract"] } +codec-adapter = { package = "reallyme-codec-adapter", version = "=0.4.5", path = "../adapter" } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", features = ["generated"] } +codec-runtime = { package = "reallyme-codec", version = "=0.4.5", path = "../codec", default-features = false, features = ["operation-contract"] } jni = { workspace = true, optional = true } zeroize = { workspace = true } diff --git a/crates/ffi/tests/general_cbor_byte_limits.rs b/crates/ffi/tests/general_cbor_byte_limits.rs new file mode 100644 index 00000000..065be097 --- /dev/null +++ b/crates/ffi/tests/general_cbor_byte_limits.rs @@ -0,0 +1,101 @@ +// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Native operation transports admit raised CBOR budgets without widening scalars. +#![allow( + missing_docs, + unsafe_code, + clippy::unwrap_used, + clippy::panic, + reason = "bounded caller-owned ABI fixtures" +)] + +use codec_proto::generated::proto::reallyme::codec::v1 as proto; +use codec_proto::{decode_json, decode_protobuf, encode_protobuf}; +use reallyme_codec_ffi::codec::{ + rm_codec_max_ffi_input_bytes, rm_codec_process_operation, rm_codec_process_operation_json, +}; +use zeroize::Zeroizing; + +type Process = unsafe extern "C" fn(*const u8, usize, *mut u8, usize, *mut usize) -> i32; + +fn call(process: Process, input: &[u8]) -> Zeroizing> { + let mut length = 0; + // SAFETY: Input remains live and the distinct aligned length is writable; + // null output with zero capacity is the ABI's documented sizing probe. + let status = unsafe { + process( + input.as_ptr(), + input.len(), + core::ptr::null_mut(), + 0, + &mut length, + ) + }; + assert_eq!( + status, + proto::CodecLegacyAbiStatus::CODEC_LEGACY_ABI_STATUS_BUFFER_TOO_SMALL as i32 + ); + let mut output = Zeroizing::new(vec![0; length]); + // SAFETY: Input, output, and length storage are distinct live allocations; + // the second call uses the complete capacity returned by the sizing probe. + let status = unsafe { + process( + input.as_ptr(), + input.len(), + output.as_mut_ptr(), + output.len(), + &mut length, + ) + }; + assert_eq!( + status, + proto::CodecLegacyAbiStatus::CODEC_LEGACY_ABI_STATUS_UNSPECIFIED as i32 + ); + assert_eq!(length, output.len()); + output +} + +#[test] +fn two_mib_general_cbor_passes_native_binary_and_json_operation_boundaries() { + const MAX_BYTES: usize = 2_097_152; + assert_eq!(rm_codec_max_ffi_input_bytes(), 1_048_576); + let mut encoded = Zeroizing::new(vec![0x5a]); + encoded.extend_from_slice( + &u32::try_from(MAX_BYTES.checked_sub(5).unwrap()) + .unwrap() + .to_be_bytes(), + ); + encoded.resize(MAX_BYTES, 0xa5); + let base64 = Zeroizing::new(codec_runtime::base64::bytes_to_base64(&encoded)); + let mut json = Zeroizing::new(String::from( + "{\"generalCborValidateExact\":{\"encoded\":\"", + )); + json.push_str(&base64); + json.push_str("\",\"options\":{\"serialization\":1,\"lengths\":1,\"floats\":1,\"ordering\":1,\"inputBytes\":\"2097152\",\"byteStringBytes\":\"2097152\"}}}"); + let request: proto::CodecApiOperationRequest = decode_json(json.as_bytes()).unwrap(); + let binary = encode_protobuf(&request).unwrap(); + let response = call(rm_codec_process_operation, &binary); + let json_response = call(rm_codec_process_operation_json, json.as_bytes()); + assert_eq!(response, json_response); + let response: proto::CodecApiOperationResponse = decode_protobuf(&response).unwrap(); + let Some(proto::codec_api_operation_response::Outcome::Result(result)) = + response.outcome.as_ref() + else { + panic!("expected successful native validation"); + }; + let Some(proto::codec_api_operation_result::Result::GeneralCborValidateExact(frame)) = + result.result.as_ref() + else { + panic!("expected native frame result"); + }; + assert_eq!( + frame.received.as_option().unwrap().length, + u64::try_from(MAX_BYTES).unwrap() + ); + assert_eq!( + frame.options.as_option().unwrap().input_bytes, + Some(u64::try_from(MAX_BYTES).unwrap()) + ); +} diff --git a/crates/hex/Cargo.toml b/crates/hex/Cargo.toml index 833d4ed4..b1a49fa4 100644 --- a/crates/hex/Cargo.toml +++ b/crates/hex/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-hex" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/jcs/Cargo.toml b/crates/jcs/Cargo.toml index 25f66544..21ad14ab 100644 --- a/crates/jcs/Cargo.toml +++ b/crates/jcs/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-jcs" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/multibase/Cargo.toml b/crates/multibase/Cargo.toml index f7af6a56..58d9d552 100644 --- a/crates/multibase/Cargo.toml +++ b/crates/multibase/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-multibase" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -19,7 +19,7 @@ name = "codec_multibase" [dependencies] base64 = { workspace = true } bs58 = { workspace = true } -codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.4", path = "../base64url" } +codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.5", path = "../base64url" } thiserror = { workspace = true } zeroize = { workspace = true } diff --git a/crates/multicodec/Cargo.toml b/crates/multicodec/Cargo.toml index 6fc92b17..97acc2af 100644 --- a/crates/multicodec/Cargo.toml +++ b/crates/multicodec/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-multicodec" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/multikey/Cargo.toml b/crates/multikey/Cargo.toml index eb300896..9ee4313e 100644 --- a/crates/multikey/Cargo.toml +++ b/crates/multikey/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-multikey" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -17,13 +17,13 @@ include = ["/src/**/*.rs", "/tests/**/*.rs", "/Cargo.toml", "/LICENSE", "/NOTICE name = "codec_multikey" [dependencies] -codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.4", path = "../multibase" } -codec-multicodec = { package = "reallyme-codec-multicodec", version = "=0.4.4", path = "../multicodec" } +codec-multibase = { package = "reallyme-codec-multibase", version = "=0.4.5", path = "../multibase" } +codec-multicodec = { package = "reallyme-codec-multicodec", version = "=0.4.5", path = "../multicodec" } thiserror = { workspace = true } zeroize = { workspace = true } [dev-dependencies] -codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.4", path = "../base64url" } +codec-base64url = { package = "reallyme-codec-base64url", version = "=0.4.5", path = "../base64url" } [lints] workspace = true diff --git a/crates/pem/Cargo.toml b/crates/pem/Cargo.toml index 194e39ec..3b98689c 100644 --- a/crates/pem/Cargo.toml +++ b/crates/pem/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-pem" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true @@ -18,7 +18,7 @@ include = ["/src/**/*.rs", "/tests/**/*.rs", "/Cargo.toml", "/README.md", "/LICE name = "codec_pem" [dependencies] -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", features = ["generated"] } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", features = ["generated"] } base64 = { workspace = true } thiserror = { workspace = true } zeroize = { workspace = true } diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index bfeb2bb9..4da78fe7 100644 --- a/crates/proto/Cargo.toml +++ b/crates/proto/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-proto" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/proto/README.md b/crates/proto/README.md index 5abd8397..51b05e1b 100644 --- a/crates/proto/README.md +++ b/crates/proto/README.md @@ -9,7 +9,7 @@ discriminated binary protobuf response. ```toml [dependencies] -reallyme-codec-proto = { version = "0.4.4", features = ["generated"] } +reallyme-codec-proto = { version = "0.4.5", features = ["generated"] } ``` The [schema](proto/reallyme/codec/v1/codec.proto) ships with the crate. For diff --git a/crates/proto/proto/reallyme/codec/v1/codec.proto b/crates/proto/proto/reallyme/codec/v1/codec.proto index c736f7d2..f3487985 100644 --- a/crates/proto/proto/reallyme/codec/v1/codec.proto +++ b/crates/proto/proto/reallyme/codec/v1/codec.proto @@ -785,12 +785,18 @@ message CodecGeneralCborOptions { CodecGeneralCborLengthPolicy lengths = 2; CodecGeneralCborFloatPolicy floats = 3; CodecGeneralCborMapOrdering ordering = 4; + // Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. optional uint64 input_bytes = 5; + // Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + // Independent of input_bytes, which applies to received encodings. optional uint64 output_bytes = 6; optional uint64 depth = 7; optional uint64 nodes = 8; optional uint64 entries = 9; + // Aggregate byte-string content across the operation: default 1,048,576; + // ceiling 2,097,152. CBOR headers count toward input/output, not this budget. optional uint64 byte_string_bytes = 10; + // Aggregate UTF-8 text: default and ceiling remain 1,048,576. optional uint64 text_bytes = 11; optional uint64 work = 12; // Omit for RFC 8949 basic-model key equality. Explicit UNSPECIFIED is unsupported. diff --git a/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.__view.rs b/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.__view.rs index b42c2255..c250ca4f 100644 --- a/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.__view.rs +++ b/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.__view.rs @@ -14458,8 +14458,13 @@ pub struct CodecGeneralCborOptionsView<'a> { pub floats: ::buffa::EnumValue, /// Field 4: `ordering` pub ordering: ::buffa::EnumValue, + /// Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// /// Field 5: `input_bytes` pub input_bytes: ::core::option::Option, + /// Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// Independent of input_bytes, which applies to received encodings. + /// /// Field 6: `output_bytes` pub output_bytes: ::core::option::Option, /// Field 7: `depth` @@ -14468,8 +14473,13 @@ pub struct CodecGeneralCborOptionsView<'a> { pub nodes: ::core::option::Option, /// Field 9: `entries` pub entries: ::core::option::Option, + /// Aggregate byte-string content across the operation: default 1,048,576; + /// ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + /// /// Field 10: `byte_string_bytes` pub byte_string_bytes: ::core::option::Option, + /// Aggregate UTF-8 text: default and ceiling remain 1,048,576. + /// /// Field 11: `text_bytes` pub text_bytes: ::core::option::Option, /// Field 12: `work` diff --git a/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.rs b/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.rs index d5e472ad..c3d36d8b 100644 --- a/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.rs +++ b/crates/proto/src/generated/buffa/reallyme.codec.v1.codec.rs @@ -26851,6 +26851,8 @@ pub struct CodecGeneralCborOptions { )] #[serde(default)] pub ordering: ::buffa::EnumValue, + /// Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// /// Field 5: `input_bytes` #[serde( rename = "inputBytes", @@ -26860,6 +26862,9 @@ pub struct CodecGeneralCborOptions { )] #[serde(default)] pub input_bytes: ::core::option::Option, + /// Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// Independent of input_bytes, which applies to received encodings. + /// /// Field 6: `output_bytes` #[serde( rename = "outputBytes", @@ -26893,6 +26898,9 @@ pub struct CodecGeneralCborOptions { )] #[serde(default)] pub entries: ::core::option::Option, + /// Aggregate byte-string content across the operation: default 1,048,576; + /// ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + /// /// Field 10: `byte_string_bytes` #[serde( rename = "byteStringBytes", @@ -26902,6 +26910,8 @@ pub struct CodecGeneralCborOptions { )] #[serde(default)] pub byte_string_bytes: ::core::option::Option, + /// Aggregate UTF-8 text: default and ceiling remain 1,048,576. + /// /// Field 11: `text_bytes` #[serde( rename = "textBytes", diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index 6aad8e5d..bad6d469 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-codec-wasm" -version = "0.4.4" +version = "0.4.5" edition.workspace = true rust-version.workspace = true publish.workspace = true @@ -16,9 +16,9 @@ description = "WASM bindings for the ReallyMe TypeScript codec package." crate-type = ["cdylib", "rlib"] [dependencies] -codec-adapter = { package = "reallyme-codec-adapter", version = "=0.4.4", path = "../adapter" } -codec-proto = { package = "reallyme-codec-proto", version = "=0.4.4", path = "../proto", default-features = false, features = ["generated"] } -codec-core = { package = "reallyme-codec", version = "=0.4.4", path = "../codec", default-features = false, features = ["operation-contract"] } +codec-adapter = { package = "reallyme-codec-adapter", version = "=0.4.5", path = "../adapter" } +codec-proto = { package = "reallyme-codec-proto", version = "=0.4.5", path = "../proto", default-features = false, features = ["generated"] } +codec-core = { package = "reallyme-codec", version = "=0.4.5", path = "../codec", default-features = false, features = ["operation-contract"] } js-sys = { workspace = true } wasm-bindgen = { workspace = true } zeroize = { workspace = true } diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 5e430ab3..08165670 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -483,7 +483,7 @@ dependencies = [ [[package]] name = "reallyme-codec" -version = "0.4.4" +version = "0.4.5" dependencies = [ "der", "reallyme-buffa", @@ -505,7 +505,7 @@ dependencies = [ [[package]] name = "reallyme-codec-base64" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-codec-proto", @@ -515,7 +515,7 @@ dependencies = [ [[package]] name = "reallyme-codec-base64url" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "thiserror", @@ -524,7 +524,7 @@ dependencies = [ [[package]] name = "reallyme-codec-cbor" -version = "0.4.4" +version = "0.4.5" dependencies = [ "cid", "half", @@ -539,7 +539,7 @@ dependencies = [ [[package]] name = "reallyme-codec-hex" -version = "0.4.4" +version = "0.4.5" dependencies = [ "thiserror", "zeroize", @@ -547,7 +547,7 @@ dependencies = [ [[package]] name = "reallyme-codec-jcs" -version = "0.4.4" +version = "0.4.5" dependencies = [ "itoa", "ryu-js", @@ -559,7 +559,7 @@ dependencies = [ [[package]] name = "reallyme-codec-multibase" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "bs58", @@ -570,14 +570,14 @@ dependencies = [ [[package]] name = "reallyme-codec-multicodec" -version = "0.4.4" +version = "0.4.5" dependencies = [ "thiserror", ] [[package]] name = "reallyme-codec-multikey" -version = "0.4.4" +version = "0.4.5" dependencies = [ "reallyme-codec-multibase", "reallyme-codec-multicodec", @@ -587,7 +587,7 @@ dependencies = [ [[package]] name = "reallyme-codec-pem" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-codec-proto", @@ -597,7 +597,7 @@ dependencies = [ [[package]] name = "reallyme-codec-proto" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-buffa", diff --git a/gen/es/reallyme/codec/v1/codec_pb.ts b/gen/es/reallyme/codec/v1/codec_pb.ts index 97346ee5..9c243d98 100644 --- a/gen/es/reallyme/codec/v1/codec_pb.ts +++ b/gen/es/reallyme/codec/v1/codec_pb.ts @@ -1769,11 +1769,16 @@ export type CodecGeneralCborOptions = Message<"reallyme.codec.v1.CodecGeneralCbo ordering: CodecGeneralCborMapOrdering; /** + * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * * @generated from field: optional uint64 input_bytes = 5; */ inputBytes?: bigint | undefined; /** + * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * Independent of input_bytes, which applies to received encodings. + * * @generated from field: optional uint64 output_bytes = 6; */ outputBytes?: bigint | undefined; @@ -1794,11 +1799,16 @@ export type CodecGeneralCborOptions = Message<"reallyme.codec.v1.CodecGeneralCbo entries?: bigint | undefined; /** + * Aggregate byte-string content across the operation: default 1,048,576; + * ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + * * @generated from field: optional uint64 byte_string_bytes = 10; */ byteStringBytes?: bigint | undefined; /** + * Aggregate UTF-8 text: default and ceiling remain 1,048,576. + * * @generated from field: optional uint64 text_bytes = 11; */ textBytes?: bigint | undefined; diff --git a/gen/java/me/really/codec/v1/CodecGeneralCborOptions.java b/gen/java/me/really/codec/v1/CodecGeneralCborOptions.java index cb71a78e..8320a659 100644 --- a/gen/java/me/really/codec/v1/CodecGeneralCborOptions.java +++ b/gen/java/me/really/codec/v1/CodecGeneralCborOptions.java @@ -198,6 +198,10 @@ private void clearOrdering() { public static final int INPUT_BYTES_FIELD_NUMBER = 5; private long inputBytes_; /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return Whether the inputBytes field is set. */ @@ -206,6 +210,10 @@ public boolean hasInputBytes() { return ((bitField0_ & 0x00000001) != 0); } /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return The inputBytes. */ @@ -214,6 +222,10 @@ public long getInputBytes() { return inputBytes_; } /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @param value The inputBytes to set. */ @@ -222,6 +234,10 @@ private void setInputBytes(long value) { inputBytes_ = value; } /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; */ private void clearInputBytes() { @@ -232,6 +248,11 @@ private void clearInputBytes() { public static final int OUTPUT_BYTES_FIELD_NUMBER = 6; private long outputBytes_; /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return Whether the outputBytes field is set. */ @@ -240,6 +261,11 @@ public boolean hasOutputBytes() { return ((bitField0_ & 0x00000002) != 0); } /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return The outputBytes. */ @@ -248,6 +274,11 @@ public long getOutputBytes() { return outputBytes_; } /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @param value The outputBytes to set. */ @@ -256,6 +287,11 @@ private void setOutputBytes(long value) { outputBytes_ = value; } /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; */ private void clearOutputBytes() { @@ -368,6 +404,11 @@ private void clearEntries() { public static final int BYTE_STRING_BYTES_FIELD_NUMBER = 10; private long byteStringBytes_; /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return Whether the byteStringBytes field is set. */ @@ -376,6 +417,11 @@ public boolean hasByteStringBytes() { return ((bitField0_ & 0x00000020) != 0); } /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return The byteStringBytes. */ @@ -384,6 +430,11 @@ public long getByteStringBytes() { return byteStringBytes_; } /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @param value The byteStringBytes to set. */ @@ -392,6 +443,11 @@ private void setByteStringBytes(long value) { byteStringBytes_ = value; } /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; */ private void clearByteStringBytes() { @@ -402,6 +458,10 @@ private void clearByteStringBytes() { public static final int TEXT_BYTES_FIELD_NUMBER = 11; private long textBytes_; /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return Whether the textBytes field is set. */ @@ -410,6 +470,10 @@ public boolean hasTextBytes() { return ((bitField0_ & 0x00000040) != 0); } /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return The textBytes. */ @@ -418,6 +482,10 @@ public long getTextBytes() { return textBytes_; } /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @param value The textBytes to set. */ @@ -426,6 +494,10 @@ private void setTextBytes(long value) { textBytes_ = value; } /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; */ private void clearTextBytes() { @@ -909,6 +981,10 @@ public Builder clearOrdering() { } /** + *
+     * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return Whether the inputBytes field is set. */ @@ -917,6 +993,10 @@ public boolean hasInputBytes() { return instance.hasInputBytes(); } /** + *
+     * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return The inputBytes. */ @@ -925,6 +1005,10 @@ public long getInputBytes() { return instance.getInputBytes(); } /** + *
+     * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @param value The inputBytes to set. * @return This builder for chaining. @@ -935,6 +1019,10 @@ public Builder setInputBytes(long value) { return this; } /** + *
+     * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return This builder for chaining. */ @@ -945,6 +1033,11 @@ public Builder clearInputBytes() { } /** + *
+     * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * Independent of input_bytes, which applies to received encodings.
+     * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return Whether the outputBytes field is set. */ @@ -953,6 +1046,11 @@ public boolean hasOutputBytes() { return instance.hasOutputBytes(); } /** + *
+     * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * Independent of input_bytes, which applies to received encodings.
+     * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return The outputBytes. */ @@ -961,6 +1059,11 @@ public long getOutputBytes() { return instance.getOutputBytes(); } /** + *
+     * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * Independent of input_bytes, which applies to received encodings.
+     * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @param value The outputBytes to set. * @return This builder for chaining. @@ -971,6 +1074,11 @@ public Builder setOutputBytes(long value) { return this; } /** + *
+     * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+     * Independent of input_bytes, which applies to received encodings.
+     * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return This builder for chaining. */ @@ -1089,6 +1197,11 @@ public Builder clearEntries() { } /** + *
+     * Aggregate byte-string content across the operation: default 1,048,576;
+     * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+     * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return Whether the byteStringBytes field is set. */ @@ -1097,6 +1210,11 @@ public boolean hasByteStringBytes() { return instance.hasByteStringBytes(); } /** + *
+     * Aggregate byte-string content across the operation: default 1,048,576;
+     * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+     * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return The byteStringBytes. */ @@ -1105,6 +1223,11 @@ public long getByteStringBytes() { return instance.getByteStringBytes(); } /** + *
+     * Aggregate byte-string content across the operation: default 1,048,576;
+     * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+     * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @param value The byteStringBytes to set. * @return This builder for chaining. @@ -1115,6 +1238,11 @@ public Builder setByteStringBytes(long value) { return this; } /** + *
+     * Aggregate byte-string content across the operation: default 1,048,576;
+     * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+     * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return This builder for chaining. */ @@ -1125,6 +1253,10 @@ public Builder clearByteStringBytes() { } /** + *
+     * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+     * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return Whether the textBytes field is set. */ @@ -1133,6 +1265,10 @@ public boolean hasTextBytes() { return instance.hasTextBytes(); } /** + *
+     * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+     * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return The textBytes. */ @@ -1141,6 +1277,10 @@ public long getTextBytes() { return instance.getTextBytes(); } /** + *
+     * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+     * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @param value The textBytes to set. * @return This builder for chaining. @@ -1151,6 +1291,10 @@ public Builder setTextBytes(long value) { return this; } /** + *
+     * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+     * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return This builder for chaining. */ diff --git a/gen/java/me/really/codec/v1/CodecGeneralCborOptionsOrBuilder.java b/gen/java/me/really/codec/v1/CodecGeneralCborOptionsOrBuilder.java index fa1a1242..74cf197f 100644 --- a/gen/java/me/really/codec/v1/CodecGeneralCborOptionsOrBuilder.java +++ b/gen/java/me/really/codec/v1/CodecGeneralCborOptionsOrBuilder.java @@ -55,22 +55,40 @@ public interface CodecGeneralCborOptionsOrBuilder extends me.really.codec.v1.CodecGeneralCborMapOrdering getOrdering(); /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return Whether the inputBytes field is set. */ boolean hasInputBytes(); /** + *
+   * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * 
+ * * optional uint64 input_bytes = 5 [json_name = "inputBytes"]; * @return The inputBytes. */ long getInputBytes(); /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return Whether the outputBytes field is set. */ boolean hasOutputBytes(); /** + *
+   * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152.
+   * Independent of input_bytes, which applies to received encodings.
+   * 
+ * * optional uint64 output_bytes = 6 [json_name = "outputBytes"]; * @return The outputBytes. */ @@ -110,22 +128,40 @@ public interface CodecGeneralCborOptionsOrBuilder extends long getEntries(); /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return Whether the byteStringBytes field is set. */ boolean hasByteStringBytes(); /** + *
+   * Aggregate byte-string content across the operation: default 1,048,576;
+   * ceiling 2,097,152. CBOR headers count toward input/output, not this budget.
+   * 
+ * * optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"]; * @return The byteStringBytes. */ long getByteStringBytes(); /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return Whether the textBytes field is set. */ boolean hasTextBytes(); /** + *
+   * Aggregate UTF-8 text: default and ceiling remain 1,048,576.
+   * 
+ * * optional uint64 text_bytes = 11 [json_name = "textBytes"]; * @return The textBytes. */ diff --git a/gen/kotlin/me/really/codec/v1/CodecGeneralCborOptionsKt.kt b/gen/kotlin/me/really/codec/v1/CodecGeneralCborOptionsKt.kt index fc62ec29..71084a05 100644 --- a/gen/kotlin/me/really/codec/v1/CodecGeneralCborOptionsKt.kt +++ b/gen/kotlin/me/really/codec/v1/CodecGeneralCborOptionsKt.kt @@ -132,6 +132,10 @@ public object CodecGeneralCborOptionsKt { } /** + * ``` + * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * ``` + * * `optional uint64 input_bytes = 5 [json_name = "inputBytes"];` */ public var inputBytes: kotlin.Long @@ -142,12 +146,20 @@ public object CodecGeneralCborOptionsKt { _builder.inputBytes = value } /** + * ``` + * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * ``` + * * `optional uint64 input_bytes = 5 [json_name = "inputBytes"];` */ public fun clearInputBytes() { _builder.clearInputBytes() } /** + * ``` + * Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * ``` + * * `optional uint64 input_bytes = 5 [json_name = "inputBytes"];` * @return Whether the inputBytes field is set. */ @@ -156,6 +168,11 @@ public object CodecGeneralCborOptionsKt { } /** + * ``` + * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * Independent of input_bytes, which applies to received encodings. + * ``` + * * `optional uint64 output_bytes = 6 [json_name = "outputBytes"];` */ public var outputBytes: kotlin.Long @@ -166,12 +183,22 @@ public object CodecGeneralCborOptionsKt { _builder.outputBytes = value } /** + * ``` + * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * Independent of input_bytes, which applies to received encodings. + * ``` + * * `optional uint64 output_bytes = 6 [json_name = "outputBytes"];` */ public fun clearOutputBytes() { _builder.clearOutputBytes() } /** + * ``` + * Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + * Independent of input_bytes, which applies to received encodings. + * ``` + * * `optional uint64 output_bytes = 6 [json_name = "outputBytes"];` * @return Whether the outputBytes field is set. */ @@ -252,6 +279,11 @@ public object CodecGeneralCborOptionsKt { } /** + * ``` + * Aggregate byte-string content across the operation: default 1,048,576; + * ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + * ``` + * * `optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"];` */ public var byteStringBytes: kotlin.Long @@ -262,12 +294,22 @@ public object CodecGeneralCborOptionsKt { _builder.byteStringBytes = value } /** + * ``` + * Aggregate byte-string content across the operation: default 1,048,576; + * ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + * ``` + * * `optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"];` */ public fun clearByteStringBytes() { _builder.clearByteStringBytes() } /** + * ``` + * Aggregate byte-string content across the operation: default 1,048,576; + * ceiling 2,097,152. CBOR headers count toward input/output, not this budget. + * ``` + * * `optional uint64 byte_string_bytes = 10 [json_name = "byteStringBytes"];` * @return Whether the byteStringBytes field is set. */ @@ -276,6 +318,10 @@ public object CodecGeneralCborOptionsKt { } /** + * ``` + * Aggregate UTF-8 text: default and ceiling remain 1,048,576. + * ``` + * * `optional uint64 text_bytes = 11 [json_name = "textBytes"];` */ public var textBytes: kotlin.Long @@ -286,12 +332,20 @@ public object CodecGeneralCborOptionsKt { _builder.textBytes = value } /** + * ``` + * Aggregate UTF-8 text: default and ceiling remain 1,048,576. + * ``` + * * `optional uint64 text_bytes = 11 [json_name = "textBytes"];` */ public fun clearTextBytes() { _builder.clearTextBytes() } /** + * ``` + * Aggregate UTF-8 text: default and ceiling remain 1,048,576. + * ``` + * * `optional uint64 text_bytes = 11 [json_name = "textBytes"];` * @return Whether the textBytes field is set. */ diff --git a/gen/swift/reallyme/codec/v1/codec.pb.swift b/gen/swift/reallyme/codec/v1/codec.pb.swift index eb3f0110..c67de9a2 100644 --- a/gen/swift/reallyme/codec/v1/codec.pb.swift +++ b/gen/swift/reallyme/codec/v1/codec.pb.swift @@ -4323,6 +4323,7 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { var ordering: ReallyMeProtoCodecGeneralCborMapOrdering = .unspecified + /// Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. var inputBytes: UInt64 { get {_inputBytes ?? 0} set {_inputBytes = newValue} @@ -4332,6 +4333,8 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `inputBytes`. Subsequent reads from it will return its default value. mutating func clearInputBytes() {self._inputBytes = nil} + /// Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// Independent of input_bytes, which applies to received encodings. var outputBytes: UInt64 { get {_outputBytes ?? 0} set {_outputBytes = newValue} @@ -4368,6 +4371,8 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `entries`. Subsequent reads from it will return its default value. mutating func clearEntries() {self._entries = nil} + /// Aggregate byte-string content across the operation: default 1,048,576; + /// ceiling 2,097,152. CBOR headers count toward input/output, not this budget. var byteStringBytes: UInt64 { get {_byteStringBytes ?? 0} set {_byteStringBytes = newValue} @@ -4377,6 +4382,7 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `byteStringBytes`. Subsequent reads from it will return its default value. mutating func clearByteStringBytes() {self._byteStringBytes = nil} + /// Aggregate UTF-8 text: default and ceiling remain 1,048,576. var textBytes: UInt64 { get {_textBytes ?? 0} set {_textBytes = newValue} diff --git a/packages/kotlin-android/README.md b/packages/kotlin-android/README.md index f8135516..990fdec6 100644 --- a/packages/kotlin-android/README.md +++ b/packages/kotlin-android/README.md @@ -5,7 +5,7 @@ libraries. Applications do not need to build or load a library manually. ```kotlin dependencies { - implementation("me.really:codec-android:0.4.4") + implementation("me.really:codec-android:0.4.5") } ``` diff --git a/packages/kotlin-android/build.gradle.kts b/packages/kotlin-android/build.gradle.kts index 2f9bf453..3294e4c6 100644 --- a/packages/kotlin-android/build.gradle.kts +++ b/packages/kotlin-android/build.gradle.kts @@ -16,7 +16,7 @@ plugins { } group = "me.really" -version = "0.4.4" +version = "0.4.5" // AGP's publication component reads these generated configurations, rather // than releaseApiElements/releaseRuntimeElements. Keep the implicit identity diff --git a/packages/kotlin-android/consumer-r8-runtime/build.gradle.kts b/packages/kotlin-android/consumer-r8-runtime/build.gradle.kts index 90e52ded..058fc60c 100644 --- a/packages/kotlin-android/consumer-r8-runtime/build.gradle.kts +++ b/packages/kotlin-android/consumer-r8-runtime/build.gradle.kts @@ -15,7 +15,7 @@ android { minSdk = 24 targetSdk = 37 versionCode = 1 - versionName = "0.4.4" + versionName = "0.4.5" } compileOptions { diff --git a/packages/kotlin/README.md b/packages/kotlin/README.md index 128bc18e..a20d279d 100644 --- a/packages/kotlin/README.md +++ b/packages/kotlin/README.md @@ -5,7 +5,7 @@ JNI libraries as platform resources. The matching library loads on first use. ```kotlin dependencies { - implementation("me.really:codec:0.4.4") + implementation("me.really:codec:0.4.5") } ``` diff --git a/packages/kotlin/build.gradle.kts b/packages/kotlin/build.gradle.kts index 95e4fbaa..174b61e3 100644 --- a/packages/kotlin/build.gradle.kts +++ b/packages/kotlin/build.gradle.kts @@ -20,7 +20,7 @@ plugins { } group = "me.really" -version = "0.4.4" +version = "0.4.5" // The JVM jar and Android AAR expose the same me.really.codec classes. // The shared capability makes Gradle reject a graph containing both. diff --git a/packages/kotlin/src/main/kotlin/me/really/codec/ReallyMeCodecRustNativeProvider.kt b/packages/kotlin/src/main/kotlin/me/really/codec/ReallyMeCodecRustNativeProvider.kt index 40e732e0..21755688 100644 --- a/packages/kotlin/src/main/kotlin/me/really/codec/ReallyMeCodecRustNativeProvider.kt +++ b/packages/kotlin/src/main/kotlin/me/really/codec/ReallyMeCodecRustNativeProvider.kt @@ -26,7 +26,7 @@ public object ReallyMeCodecRustNativeProvider { private const val EXPECTED_CODEC_ABI_VERSION: Int = 6 private const val EXPECTED_CODEC_PACKAGE_MAJOR: Int = 0 private const val EXPECTED_CODEC_PACKAGE_MINOR: Int = 4 - private const val EXPECTED_CODEC_PACKAGE_PATCH: Int = 4 + private const val EXPECTED_CODEC_PACKAGE_PATCH: Int = 5 private const val MAX_MANAGED_FFI_LIMIT_BYTES: Long = Int.MAX_VALUE.toLong() private const val ALLOW_UNVERIFIED_NATIVE_PROPERTY: String = "reallyme.codec.allowUnverifiedNative" diff --git a/packages/kotlin/src/test/kotlin/me/really/codec/GeneralCborReceiptOptionsTest.kt b/packages/kotlin/src/test/kotlin/me/really/codec/GeneralCborReceiptOptionsTest.kt index ba68513a..947d7176 100644 --- a/packages/kotlin/src/test/kotlin/me/really/codec/GeneralCborReceiptOptionsTest.kt +++ b/packages/kotlin/src/test/kotlin/me/really/codec/GeneralCborReceiptOptionsTest.kt @@ -8,12 +8,55 @@ import com.google.protobuf.ByteString import me.really.codec.v1.CodecApiOperationRequest import me.really.codec.v1.CodecApiOperationResponse import me.really.codec.v1.CodecApiOperationResult +import me.really.codec.v1.CodecGeneralCborErrorReason +import me.really.codec.v1.CodecGeneralCborFloatPolicy +import me.really.codec.v1.CodecGeneralCborLengthPolicy +import me.really.codec.v1.CodecGeneralCborMapOrdering +import me.really.codec.v1.CodecGeneralCborOptions +import me.really.codec.v1.CodecGeneralCborSerialization import me.really.codec.v1.CodecGeneralCborSourceRequest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue class GeneralCborReceiptOptionsTest { + @Test + fun explicitTwoMiBBudgetPassesNativeTransportWithoutChangingDefaults() { + System + .getProperty("reallyme.codec.testLibraryPath") + ?.takeIf { it.isNotBlank() } + ?.let { ReallyMeCodecRustNativeProvider.loadLibrary(it) } + val encoded = ByteArray(2_097_152) + encoded.fill(0xa5.toByte()) + byteArrayOf(0x5a, 0x00, 0x1f, 0xff.toByte(), 0xfb.toByte()).copyInto(encoded) + try { + val source = CodecGeneralCborSourceRequest.newBuilder().setEncoded(ByteString.copyFrom(encoded)) + val request = CodecApiOperationRequest.newBuilder().setGeneralCborValidateExact(source) + val rejected = CodecApiOperationResponse.parseFrom(ReallyMeCodec.processOperation(request.build().toByteArray())) + assertEquals(CodecApiOperationResponse.OutcomeCase.ERROR, rejected.outcomeCase) + assertEquals(CodecGeneralCborErrorReason.CODEC_GENERAL_CBOR_ERROR_REASON_INPUT_LIMIT, rejected.error.generalCbor.detail) + val options = + CodecGeneralCborOptions + .newBuilder() + .setSerialization(CodecGeneralCborSerialization.CODEC_GENERAL_CBOR_SERIALIZATION_RECEIVED) + .setLengths(CodecGeneralCborLengthPolicy.CODEC_GENERAL_CBOR_LENGTH_POLICY_DEFINITE_ONLY) + .setFloats(CodecGeneralCborFloatPolicy.CODEC_GENERAL_CBOR_FLOAT_POLICY_ALL) + .setOrdering(CodecGeneralCborMapOrdering.CODEC_GENERAL_CBOR_MAP_ORDERING_RECEIVED) + .setInputBytes(encoded.size.toLong()) + .setByteStringBytes(encoded.size.toLong()) + source.setOptions(options) + request.setGeneralCborValidateExact(source) + val accepted = CodecApiOperationResponse.parseFrom(ReallyMeCodec.processOperation(request.build().toByteArray())) + assertEquals(CodecApiOperationResponse.OutcomeCase.RESULT, accepted.outcomeCase) + val frame = accepted.result.generalCborValidateExact + assertEquals(encoded.size.toLong(), frame.received.length) + assertEquals(encoded.size.toLong(), frame.options.inputBytes) + assertEquals(1_048_576L, frame.options.outputBytes) + } finally { + encoded.fill(0) + } + } + @Test fun collectionOptionsAreSharedAndStandaloneOptionsRemainPresent() { System diff --git a/packages/kotlin/src/test/kotlin/me/really/codec/NativeProviderSafetyTest.kt b/packages/kotlin/src/test/kotlin/me/really/codec/NativeProviderSafetyTest.kt index 80ef0691..d45698a8 100644 --- a/packages/kotlin/src/test/kotlin/me/really/codec/NativeProviderSafetyTest.kt +++ b/packages/kotlin/src/test/kotlin/me/really/codec/NativeProviderSafetyTest.kt @@ -45,7 +45,8 @@ class NativeProviderSafetyTest { assertFalse(ReallyMeCodecRustNativeProvider.isCompatibleAbiVersion(5)) assertFalse(ReallyMeCodecRustNativeProvider.isCompatibleAbiVersion(0)) - assertTrue(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 4)) + assertTrue(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 5)) + assertFalse(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 4)) assertFalse(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 3)) assertFalse(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 2)) assertFalse(ReallyMeCodecRustNativeProvider.isCompatiblePackageVersion(0, 4, 1)) diff --git a/packages/swift/README.md b/packages/swift/README.md index f398f057..278a8417 100644 --- a/packages/swift/README.md +++ b/packages/swift/README.md @@ -6,7 +6,7 @@ Building from source requires Swift 6.3. ## Install ```swift -.package(url: "https://github.com/reallyme/codec", from: "0.4.4") +.package(url: "https://github.com/reallyme/codec", from: "0.4.5") ``` Add `.product(name: "ReallyMeCodec", package: "codec")` to your target. diff --git a/packages/swift/Sources/ReallyMeCodec/CallCodecWithRustCAbi.swift b/packages/swift/Sources/ReallyMeCodec/CallCodecWithRustCAbi.swift index 3949b946..e21c9dc5 100644 --- a/packages/swift/Sources/ReallyMeCodec/CallCodecWithRustCAbi.swift +++ b/packages/swift/Sources/ReallyMeCodec/CallCodecWithRustCAbi.swift @@ -13,7 +13,7 @@ import Foundation private let expectedCodecAbiVersion: UInt32 = 6 private let expectedCodecPackageMajor: UInt32 = 0 private let expectedCodecPackageMinor: UInt32 = 4 -private let expectedCodecPackagePatch: UInt32 = 4 +private let expectedCodecPackagePatch: UInt32 = 5 // Shared transport cap includes JSON expansion and operation framing. Its value // is derived and checked by scripts/generate_codec_limits.mjs. private let maxProtoJsonRequestLength = 22_373_720 diff --git a/packages/swift/Sources/ReallyMeCodec/Generated/CodecProto.swift b/packages/swift/Sources/ReallyMeCodec/Generated/CodecProto.swift index eb3f0110..c67de9a2 100644 --- a/packages/swift/Sources/ReallyMeCodec/Generated/CodecProto.swift +++ b/packages/swift/Sources/ReallyMeCodec/Generated/CodecProto.swift @@ -4323,6 +4323,7 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { var ordering: ReallyMeProtoCodecGeneralCborMapOrdering = .unspecified + /// Encoded input, including CBOR headers: default 1,048,576; ceiling 2,097,152. var inputBytes: UInt64 { get {_inputBytes ?? 0} set {_inputBytes = newValue} @@ -4332,6 +4333,8 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `inputBytes`. Subsequent reads from it will return its default value. mutating func clearInputBytes() {self._inputBytes = nil} + /// Encoded output, including CBOR headers: default 1,048,576; ceiling 2,097,152. + /// Independent of input_bytes, which applies to received encodings. var outputBytes: UInt64 { get {_outputBytes ?? 0} set {_outputBytes = newValue} @@ -4368,6 +4371,8 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `entries`. Subsequent reads from it will return its default value. mutating func clearEntries() {self._entries = nil} + /// Aggregate byte-string content across the operation: default 1,048,576; + /// ceiling 2,097,152. CBOR headers count toward input/output, not this budget. var byteStringBytes: UInt64 { get {_byteStringBytes ?? 0} set {_byteStringBytes = newValue} @@ -4377,6 +4382,7 @@ nonisolated struct ReallyMeProtoCodecGeneralCborOptions: Sendable { /// Clears the value of `byteStringBytes`. Subsequent reads from it will return its default value. mutating func clearByteStringBytes() {self._byteStringBytes = nil} + /// Aggregate UTF-8 text: default and ceiling remain 1,048,576. var textBytes: UInt64 { get {_textBytes ?? 0} set {_textBytes = newValue} diff --git a/packages/swift/Tests/ReallyMeCodecTests/GeneralCborReceiptOptionsTests.swift b/packages/swift/Tests/ReallyMeCodecTests/GeneralCborReceiptOptionsTests.swift index b047843d..a9b1861d 100644 --- a/packages/swift/Tests/ReallyMeCodecTests/GeneralCborReceiptOptionsTests.swift +++ b/packages/swift/Tests/ReallyMeCodecTests/GeneralCborReceiptOptionsTests.swift @@ -8,6 +8,44 @@ import SwiftProtobuf import XCTest final class GeneralCborReceiptOptionsTests: XCTestCase { + func testExplicitTwoMiBBudgetPassesNativeTransportWithoutChangingDefaults() throws { + let codec = try ReallyMeCodecTests.configuredCodec() + let encodedLength = 2_097_152 + var encoded = Data([0x5a, 0x00, 0x1f, 0xff, 0xfb]) + encoded.append(Data(repeating: 0xa5, count: encodedLength - encoded.count)) + defer { encoded.resetBytes(in: encoded.startIndex.. ({ + serialization: CodecGeneralCborSerialization.RECEIVED, + lengths: CodecGeneralCborLengthPolicy.DEFINITE_ONLY, + floats: CodecGeneralCborFloatPolicy.ALL, + ordering: CodecGeneralCborMapOrdering.RECEIVED, + inputBytes: BigInt(MAX_BYTES), outputBytes: BigInt(MAX_BYTES), byteStringBytes: BigInt(MAX_BYTES), +}); + +function wire(total) { + const encoded = new Uint8Array(total).fill(0xa5); + encoded[0] = 0x5a; + new DataView(encoded.buffer).setUint32(1, total - 5, false); + return encoded; +} + +function execute(operation, check) { + const request = create(CodecApiOperationRequestSchema, { operation }); + const binary = toBinary(CodecApiOperationRequestSchema, request); + const json = new TextEncoder().encode(toJsonString(CodecApiOperationRequestSchema, request)); + const response = processOperation(binary); + const jsonResponse = processOperationJson(json); + try { + assert.deepEqual(response, jsonResponse); + check(fromBinary(CodecApiOperationResponseSchema, response)); + } finally { + binary.fill(0); + json.fill(0); + response.fill(0); + jsonResponse.fill(0); + } +} + +function failure(expected) { + return (response) => { + assert.equal(response.outcome.case, "error"); + assert.equal(response.outcome.value.origin, CodecErrorOrigin.CALLER); + assert.equal(response.outcome.value.error.case, "generalCbor"); + assert.equal(response.outcome.value.error.value.detail, expected); + }; +} + +function success(operation, check = () => {}) { + return (response) => { + assert.equal(response.outcome.case, "result"); + assert.equal(response.outcome.value.result.case, operation); + const result = response.outcome.value.result.value; + try { check(result); } finally { + if (result.value instanceof Uint8Array) result.value.fill(0); + } + }; +} + +test("general-CBOR input budgets include headers and retain the one-MiB default through WASM", () => { + for (const size of [DEFAULT_BYTES, DEFAULT_BYTES + 1, MAX_BYTES]) { + const encoded = wire(size); + try { + execute({ case: "generalCborValidateExact", value: { encoded } }, size > DEFAULT_BYTES + ? failure(CodecGeneralCborErrorReason.INPUT_LIMIT) + : success("generalCborValidateExact")); + for (const operation of ["generalCborFrameExact", "generalCborFramePrefix", "generalCborValidateExact", "generalCborValidatePrefix"]) { + execute({ case: operation, value: { encoded, options: { ...options(), inputBytes: BigInt(size) } } }, success(operation, (frame) => { + assert.equal(frame.received.offset, 0n); + assert.equal(frame.received.length, BigInt(size)); + assert.equal(frame.options.inputBytes, BigInt(size)); + })); + } + execute({ case: "generalCborValidateExact", value: { encoded, options: { ...options(), inputBytes: BigInt(size - 1) } } }, failure(CodecGeneralCborErrorReason.INPUT_LIMIT)); + execute({ case: "generalCborValidateExact", value: { encoded, options: { ...options(), byteStringBytes: BigInt(size - 6) } } }, failure(CodecGeneralCborErrorReason.BYTE_STRING_LIMIT)); + } finally { encoded.fill(0); } + } + const encoded = wire(MAX_BYTES + 1); + try { + execute({ case: "generalCborFrameExact", value: { encoded, options: options() } }, failure(CodecGeneralCborErrorReason.INPUT_LIMIT)); + } finally { encoded.fill(0); } +}); + +test("general-CBOR output and aggregate budgets are independently enforced through WASM", () => { + const encoded = wire(MAX_BYTES); + const value = { value: { case: "bytesValue", value: { value: encoded.subarray(5) } } }; + try { + execute({ case: "generalCborEncode", value: { value, options: { ...options(), inputBytes: 0n } } }, success("generalCborEncode", (result) => assert.deepEqual(result.value, encoded))); + execute({ case: "generalCborEncode", value: { value, options: { ...options(), outputBytes: BigInt(MAX_BYTES - 1) } } }, failure(CodecGeneralCborErrorReason.OUTPUT_LIMIT)); + execute({ case: "generalCborEncode", value: { value, options: { ...options(), byteStringBytes: BigInt(encoded.length - 6) } } }, failure(CodecGeneralCborErrorReason.BYTE_STRING_LIMIT)); + execute({ case: "generalCborEncode", value: { value } }, failure(CodecGeneralCborErrorReason.BYTE_STRING_LIMIT)); + const received = { value: { case: "receivedValue", value: { value: encoded } } }; + execute({ case: "generalCborEncode", value: { value: received, options: { ...options(), inputBytes: BigInt(DEFAULT_BYTES) } } }, failure(CodecGeneralCborErrorReason.INPUT_LIMIT)); + } finally { encoded.fill(0); } +}); + +test("general-CBOR cursor and child receipts retain raised budgets through WASM", () => { + const encoded = wire(DEFAULT_BYTES + 5); + const parent = new Uint8Array(encoded.length + 1); + parent[0] = 0x81; + parent.set(encoded, 1); + try { + execute({ case: "generalCborCursor", value: { encoded, options: options() } }, success("generalCborCursor", (result) => { + assert.equal(result.values.length, 1); + assert.equal(result.values[0].received.length, BigInt(encoded.length)); + assert.equal(result.options.inputBytes, BigInt(MAX_BYTES)); + })); + execute({ case: "generalCborInspect", value: { encoded: parent, options: options(), validate: true, inspection: CodecGeneralCborInspection.CHILDREN } }, success("generalCborInspect", (result) => { + assert.equal(result.value.case, "children"); + assert.equal(result.value.value.values[0].received.offset, 1n); + assert.equal(result.value.value.options.byteStringBytes, BigInt(MAX_BYTES)); + })); + } finally { encoded.fill(0); parent.fill(0); } +}); + +test("general-CBOR ceiling-plus-one and uint64 overflow-sized limits fail through WASM", () => { + for (const value of [BigInt(MAX_BYTES + 1), 18_446_744_073_709_551_615n]) { + for (const field of ["inputBytes", "outputBytes", "byteStringBytes"]) { + execute({ case: "generalCborFrameExact", value: { encoded: Uint8Array.of(0), options: { ...options(), [field]: value } } }, failure(CodecGeneralCborErrorReason.INVALID_LIMIT)); + } + } +}); + +test("general-CBOR aggregate and embedded budgets remain separate through WASM", () => { + const child = wire(DEFAULT_BYTES / 2 + 5); + const array = new Uint8Array(child.length * 2 + 1); + array[0] = 0x82; + array.set(child, 1); + array.set(child, child.length + 1); + const inner = wire(DEFAULT_BYTES + 5); + const outer = new Uint8Array(inner.length + 7); + outer.set([0xd8, 0x18, 0x5a]); + new DataView(outer.buffer).setUint32(3, inner.length, false); + outer.set(inner, 7); + try { + execute({ case: "generalCborValidateExact", value: { encoded: array, options: { ...options(), byteStringBytes: BigInt(DEFAULT_BYTES) } } }, success("generalCborValidateExact")); + execute({ case: "generalCborValidateExact", value: { encoded: array, options: { ...options(), byteStringBytes: BigInt(DEFAULT_BYTES - 1) } } }, failure(CodecGeneralCborErrorReason.BYTE_STRING_LIMIT)); + execute({ case: "generalCborValidateEmbedded", value: { encoded: outer, outerOptions: options() } }, failure(CodecGeneralCborErrorReason.INPUT_LIMIT)); + execute({ case: "generalCborValidateEmbedded", value: { encoded: outer, outerOptions: options(), embeddedOptions: options() } }, success("generalCborValidateEmbedded", (frame) => { + assert.equal(frame.received.offset, 7n); + assert.equal(frame.received.length, BigInt(inner.length)); + })); + } finally { child.fill(0); array.fill(0); inner.fill(0); outer.fill(0); } +}); diff --git a/probes/der-feature-unification/Cargo.lock b/probes/der-feature-unification/Cargo.lock index 3fe881d4..7f552791 100644 --- a/probes/der-feature-unification/Cargo.lock +++ b/probes/der-feature-unification/Cargo.lock @@ -104,7 +104,7 @@ dependencies = [ [[package]] name = "reallyme-codec" -version = "0.4.4" +version = "0.4.5" dependencies = [ "der", "reallyme-codec-proto", @@ -113,7 +113,7 @@ dependencies = [ [[package]] name = "reallyme-codec-proto" -version = "0.4.4" +version = "0.4.5" dependencies = [ "base64", "reallyme-buffa", @@ -125,7 +125,7 @@ dependencies = [ [[package]] name = "reallyme-der-feature-unification-probe" -version = "0.4.4" +version = "0.4.5" dependencies = [ "der", "reallyme-codec", diff --git a/probes/der-feature-unification/Cargo.toml b/probes/der-feature-unification/Cargo.toml index 42f410d5..77e74e5e 100644 --- a/probes/der-feature-unification/Cargo.toml +++ b/probes/der-feature-unification/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-der-feature-unification-probe" -version = "0.4.4" +version = "0.4.5" edition = "2021" publish = false license = "MIT OR Apache-2.0" diff --git a/probes/jcs-feature-unification/Cargo.lock b/probes/jcs-feature-unification/Cargo.lock index 8320c7c1..e3ff2982 100644 --- a/probes/jcs-feature-unification/Cargo.lock +++ b/probes/jcs-feature-unification/Cargo.lock @@ -62,7 +62,7 @@ dependencies = [ [[package]] name = "reallyme-codec-jcs" -version = "0.4.4" +version = "0.4.5" dependencies = [ "itoa", "ryu-js", @@ -74,7 +74,7 @@ dependencies = [ [[package]] name = "reallyme-jcs-feature-unification-probe" -version = "0.4.4" +version = "0.4.5" dependencies = [ "reallyme-codec-jcs", "serde_json", diff --git a/probes/jcs-feature-unification/Cargo.toml b/probes/jcs-feature-unification/Cargo.toml index 7e5e86ad..ac154c39 100644 --- a/probes/jcs-feature-unification/Cargo.toml +++ b/probes/jcs-feature-unification/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "reallyme-jcs-feature-unification-probe" -version = "0.4.4" +version = "0.4.5" edition = "2021" publish = false diff --git a/scripts/check_release_readiness.mjs b/scripts/check_release_readiness.mjs index 8f039bc2..a28a8d9f 100644 --- a/scripts/check_release_readiness.mjs +++ b/scripts/check_release_readiness.mjs @@ -376,8 +376,8 @@ for (const workflow of [".github/workflows/fuzz.yml", ".github/workflows/fuzz-sc }); } -const codecPackageVersion = "0.4.4"; -const codecProtoPackageVersion = "0.4.4"; +const codecPackageVersion = "0.4.5"; +const codecProtoPackageVersion = "0.4.5"; assertContains("Package.swift", `let ffiArtifactVersion = "${codecPackageVersion}"`); // The probes are separate Cargo workspaces. Root workspace metadata cannot // detect a release bump that leaves their own lockfile package entries stale. @@ -2192,7 +2192,7 @@ assertContains(".github/workflows/kotlin-android-package-release.yml", "Sign and assertNotContains(".github/workflows/kotlin-android-package-release.yml", "bundleReleaseAar"); assertContains(".github/workflows/kotlin-android-package-preflight.yml", "requireFullNativeResources=true"); assertContains("packages/kotlin/settings.gradle.kts", 'rootProject.name = "reallyme-codec"'); -assertContains("packages/kotlin/README.md", "me.really:codec:0.4.4"); +assertContains("packages/kotlin/README.md", "me.really:codec:0.4.5"); assertContains("packages/kotlin/README.md", "JNI libraries as platform resources"); assertContains( "packages/kotlin/src/main/kotlin/me/really/codec/ReallyMeCodecRustNativeProvider.kt", @@ -2947,7 +2947,7 @@ assertContains("scripts/test_android_consumer_r8_runtime.sh", "$SDKMANAGER\" \"e assertContains("scripts/test_android_consumer_r8_runtime.sh", "Android AVD was not available after creation"); assertContains("scripts/test_android_consumer_r8_runtime.sh", "$AVDMANAGER\" create avd --force"); assertContains("scripts/test_android_consumer_r8_runtime.sh", "Android consumer R8 runtime gate passed"); -assertContains("packages/kotlin-android/README.md", "me.really:codec-android:0.4.4"); +assertContains("packages/kotlin-android/README.md", "me.really:codec-android:0.4.5"); assertContains( "packages/kotlin-android/gradle.properties", "org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8", @@ -3031,7 +3031,7 @@ assertContains(".github/workflows/release-readiness.yml", "Test TypeScript codec assertContains(".github/workflows/npm-package-preflight.yml", "Test TypeScript codec package in browser"); assertContains("README.md", "https://www.npmjs.com/package/@reallyme/codec"); -assertContains("README.md", "me.really:codec:0.4.4"); +assertContains("README.md", "me.really:codec:0.4.5"); assertContains("README.md", "reallyme-codec-proto"); assertContains("README.md", "`me.really:codec-android` AAR"); assertContains("CONTRACT.md", "crates/proto/proto/reallyme/codec/v1/codec.proto"); diff --git a/scripts/maven-central-bundle.local.sh b/scripts/maven-central-bundle.local.sh index c7b8f387..bf66c0e9 100755 --- a/scripts/maven-central-bundle.local.sh +++ b/scripts/maven-central-bundle.local.sh @@ -12,6 +12,11 @@ fail() { exit 1 } +if [[ "$#" -eq 0 ]]; then + script_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)" + current_version="$(sed -n 's/^version = "\([^"]*\)"$/\1/p' "$script_root/packages/kotlin/build.gradle.kts")" + set -- "${MAVEN_RELEASE_VERSION:-$current_version}" "$(git -C "$script_root" rev-parse --verify HEAD)" +fi [[ "$#" -eq 2 ]] || fail "usage: ./scripts/maven-central-bundle.local.sh VERSION SOURCE_SHA" readonly version="$1" source_sha="$2" [[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || @@ -41,7 +46,7 @@ if ! git ls-files --error-unmatch -- "$adapter" >/dev/null 2>&1 || fail "provide the tracked, executable $adapter" fi -output_dir="${MAVEN_CENTRAL_OUTPUT_DIR:-"$repo_root/build/maven-central-upload/out"}" +output_dir="${MAVEN_CENTRAL_OUTPUT_DIR:-"${MAVEN_CENTRAL_WORK_DIR:-"$repo_root/build/maven-central-upload"}/out"}" [[ "$output_dir" == /* ]] || fail "MAVEN_CENTRAL_OUTPUT_DIR must be absolute" mkdir -p -- "$output_dir" output_dir="$(cd -- "$output_dir" && pwd -P)" diff --git a/scripts/maven_central_bundle.test.mjs b/scripts/maven_central_bundle.test.mjs index 43e0ac22..92d6766f 100644 --- a/scripts/maven_central_bundle.test.mjs +++ b/scripts/maven_central_bundle.test.mjs @@ -20,6 +20,13 @@ function fixture(t) { mkdirSync(join(repo, "scripts"), { recursive: true }); mkdirSync(tools); mkdirSync(output); + if (process.platform === "darwin") { + // Exercise the system Bash used on macOS runners, even with Homebrew Bash installed. + symlinkSync("/bin/bash", join(tools, "bash")); + } + const manifest = join(repo, "packages/kotlin/build.gradle.kts"); + mkdirSync(join(repo, "packages/kotlin"), { recursive: true }); + writeFileSync(manifest, 'version = "1.2.3"\n'); const helper = join(repo, "scripts/maven-central-bundle.local.sh"); const calls = join(root, "gpg-calls"); const pom = "sample release\n"; @@ -63,24 +70,32 @@ function fixture(t) { assert.equal(zip.status, 0, zip.stderr); const sha = "1234567890abcdef".repeat(2) + "12345678"; executable(join(tools, "git"), ` + if [[ "$1" == -C ]]; then + test "$2" = "$FIXTURE_REPOSITORY" || exit 79 + shift 2 + fi case "\${1}" in - rev-parse) printf '%s\\n' '${sha}' ;; - diff|ls-files) exit 0 ;; + rev-parse) + if [[ "$BUNDLE_SCENARIO" == missing-head ]]; then exit 1; fi + printf '%s\\n' '${sha}' ;; + diff) [[ "$BUNDLE_SCENARIO" != dirty ]] ;; + ls-files) exit 0 ;; *) exit 79 ;; esac `); writeFileSync(calls, ""); - const run = (version, overrides = {}, source = sha) => spawnSync(helper, [version, source], { + const run = (version, overrides = {}, source = sha) => spawnSync(helper, version === undefined ? [] : [version, source], { cwd: root, encoding: "utf8", env: { ...process.env, PATH: `${tools}${delimiter}${process.env.PATH}`, GPG_CALLS: calls, REAL_ZIP: zip.stdout.trim(), BUNDLE_SCENARIO: "", + FIXTURE_REPOSITORY: repo, MAVEN_RELEASE_VERSION: "", MAVEN_CENTRAL_WORK_DIR: "", MAVEN_SIGNING_KEY_ID: "1234567890ABCDEF", MAVEN_SIGNING_PASSWORD: "fixture-only", MAVEN_CENTRAL_OUTPUT_DIR: output, ...overrides, }, }); - return { run, output, calls, pom }; + return { run, root, output, calls, pom, manifest }; } test("Maven bundle template verifies each signature and retains every completed ZIP", { skip: process.platform === "win32" }, (t) => { @@ -132,6 +147,56 @@ test("Maven bundle template preserves prior archives when staging, signing, or Z } }); +test("Maven bundle without arguments selects the package version and current checkout from another directory", { skip: process.platform === "win32" }, (t) => { + const { run, output } = fixture(t); + const result = run(); + const archive = join(output, "reallyme-maven-central-1.2.3.zip"); + assert.equal(result.status, 0, result.stderr); + assert.equal(result.stdout.trim(), archive); + assert.deepEqual(readdirSync(output), ["reallyme-maven-central-1.2.3.zip"]); +}); + +test("Maven bundle accepts a default version override and preserves explicit argument precedence", { skip: process.platform === "win32" }, (t) => { + const { run, output } = fixture(t); + const selected = run(undefined, { MAVEN_RELEASE_VERSION: "1.2.4" }); + assert.equal(selected.status, 0, selected.stderr); + assert.equal(selected.stdout.trim(), join(output, "reallyme-maven-central-1.2.4.zip")); + const explicit = run("1.2.5", { MAVEN_RELEASE_VERSION: "9.9.9" }); + assert.equal(explicit.status, 0, explicit.stderr); + assert.equal(explicit.stdout.trim(), join(output, "reallyme-maven-central-1.2.5.zip")); +}); + +test("Maven bundle defaults reject invalid versions, unavailable commits, and dirty tracked files before signing", { skip: process.platform === "win32" }, (t) => { + const { run, output, calls, manifest } = fixture(t); + for (const [contents, overrides, diagnostic] of [ + ["", {}, /stable release version/u], + ['version = "1.2.3"\nversion = "1.2.4"\n', {}, /stable release version/u], + ['version = "1.2.3"\n', { MAVEN_RELEASE_VERSION: "1.2.4-rc.1" }, /stable release version/u], + ['version = "1.2.3"\n', { BUNDLE_SCENARIO: "missing-head" }, /full source SHA/u], + ['version = "1.2.3"\n', { BUNDLE_SCENARIO: "dirty" }, /unchanged tracked files/u], + ]) { + writeFileSync(manifest, contents); + const result = run(undefined, overrides); + assert.equal(result.status, 1, result.stderr); + assert.match(result.stderr, diagnostic); + assert.equal(result.stdout, ""); + assert.deepEqual(readdirSync(output), []); + assert.equal(readFileSync(calls, "utf8"), ""); + } +}); + +test("Maven bundle uses the work directory fallback while retaining explicit output precedence", { skip: process.platform === "win32" }, (t) => { + const { run, root, output } = fixture(t); + const work = join(root, "bundle work"); + const selected = run(undefined, { MAVEN_CENTRAL_OUTPUT_DIR: "", MAVEN_CENTRAL_WORK_DIR: work }); + assert.equal(selected.status, 0, selected.stderr); + assert.equal(selected.stdout.trim(), join(work, "out/reallyme-maven-central-1.2.3.zip")); + const explicit = run(undefined, { MAVEN_CENTRAL_WORK_DIR: work }); + assert.equal(explicit.status, 0, explicit.stderr); + assert.equal(explicit.stdout.trim(), join(output, "reallyme-maven-central-1.2.3.zip")); + assert.deepEqual(readdirSync(join(work, "out")), ["reallyme-maven-central-1.2.3.zip"]); +}); + function publicationFixture(t) { const root = realpathSync(mkdtempSync(join(tmpdir(), "codec-maven-publication-"))); t.after(() => rmSync(root, { recursive: true, force: true })); diff --git a/scripts/publish_crates_in_order.mjs b/scripts/publish_crates_in_order.mjs index f21dda65..a2bcdc65 100644 --- a/scripts/publish_crates_in_order.mjs +++ b/scripts/publish_crates_in_order.mjs @@ -284,7 +284,7 @@ function packageChecksum(pkg) { async function publishedChecksum(pkg) { const response = await fetch( `https://crates.io/api/v1/crates/${encodeURIComponent(pkg.name)}/${encodeURIComponent(pkg.version)}`, - { headers: { "User-Agent": "reallyme-codec-release/0.4.4" }, signal: AbortSignal.timeout(20000) }, + { headers: { "User-Agent": "reallyme-codec-release/0.4.5" }, signal: AbortSignal.timeout(20000) }, ); if (response.status === 404) { return null; diff --git a/scripts/run_pinned_release_readiness.mjs b/scripts/run_pinned_release_readiness.mjs index 569d88be..1487b157 100644 --- a/scripts/run_pinned_release_readiness.mjs +++ b/scripts/run_pinned_release_readiness.mjs @@ -16,7 +16,7 @@ const RELEASE_READINESS_COMMIT = "16aab5287de498e858ff3b85d9e66d7c9f7ebb74"; const RELEASE_READINESS_CORE_SHA256 = "56ae3823215f5bca908d2fce3c9304d4ea6bab0334038f37ebe33023dadb8594"; const LOCAL_CHECKER_SHA256 = - "150b273e2ac44dd45d58da0df5dc727f6360b3b45830dc4d3eac06c03feb929e"; + "e41ab3a680c1df283d572ec8fced7d1071550b5afc507d20103c6a6b96429b66"; const RELEASE_READINESS_CORE_URL = `https://raw.githubusercontent.com/reallyme/release-readiness/${RELEASE_READINESS_COMMIT}/core.mjs`; const RELEASE_READINESS_RUNNER_SHA256 =