From cd9db60b7cd68828d66c8085482740246b3f0be3 Mon Sep 17 00:00:00 2001 From: Trevor Klingler Date: Tue, 22 Apr 2025 17:06:28 -0600 Subject: [PATCH 1/2] add `uncapped_max_size` feature to allow increasing max BSON size --- Cargo.toml | 3 +++ README.md | 1 + src/de/mod.rs | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f26a1091..8bf6b31f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,9 @@ uuid-1 = [] time-0_3 = [] # If enabled, implement Hash/Eq for Bson and Document hashable = [] +# If enabled, the maximum document size will be increased from the MongoDB cap +# of 16 MB to the BSON spec maximum size of 2^31 - 1 +uncapped_max_size = [] serde_path_to_error = ["dep:serde_path_to_error"] # if enabled, include serde_with interop. # should be used in conjunction with chrono-0_4 or uuid-0_8. diff --git a/README.md b/README.md index 26ce2700..9b466092 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no | | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | serde_path_to_error | no | | `hashable` | Implement `core::hash::Hash` and `std::cmp::Eq` on `Bson` and `Document`. | n/a | no | +| `uncapped_max_size` | Increase the maximum document size will be increased from the MongoDB cap of 16 MB to the BSON spec maximum size of 2^31 - 1 bytes. | n/a | no | ## Overview of the BSON Format diff --git a/src/de/mod.rs b/src/de/mod.rs index 1ee8e5a4..f9f6814c 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -47,7 +47,10 @@ pub(crate) use self::serde::{convert_unsigned_to_signed_raw, BsonVisitor}; pub(crate) use self::raw::Deserializer as RawDeserializer; +#[cfg(not(feature = "uncapped_max_size"))] pub(crate) const MAX_BSON_SIZE: i32 = 16 * 1024 * 1024; +#[cfg(feature = "uncapped_max_size")] +pub(crate) const MAX_BSON_SIZE: i32 = i32::MAX; pub(crate) const MIN_BSON_DOCUMENT_SIZE: i32 = 4 + 1; // 4 bytes for length, one byte for null terminator pub(crate) const MIN_BSON_STRING_SIZE: i32 = 4 + 1; // 4 bytes for length, one byte for null terminator pub(crate) const MIN_CODE_WITH_SCOPE_SIZE: i32 = 4 + MIN_BSON_STRING_SIZE + MIN_BSON_DOCUMENT_SIZE; From 445f4a9ffbb3cb1fff8aa799539f3efb468e217e Mon Sep 17 00:00:00 2001 From: Trevor Klingler Date: Tue, 22 Apr 2025 18:32:56 -0600 Subject: [PATCH 2/2] fix typo in `uncapped_max_size` feature table in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b466092..2f230d80 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no | | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | serde_path_to_error | no | | `hashable` | Implement `core::hash::Hash` and `std::cmp::Eq` on `Bson` and `Document`. | n/a | no | -| `uncapped_max_size` | Increase the maximum document size will be increased from the MongoDB cap of 16 MB to the BSON spec maximum size of 2^31 - 1 bytes. | n/a | no | +| `uncapped_max_size` | Increase the maximum document size from the MongoDB cap of 16 MB to the BSON spec maximum size of 2^31 - 1 bytes. | n/a | no | ## Overview of the BSON Format