Skip to content

Commit 5cef3b6

Browse files
committed
fixup! Add configurable request body size with 1GB hard limit
Addresses the following: - read bind address correctly, - add appropriate unwrap documentation, - drop ref to mrbs because usize impls clone, - clone large object, and - assert_eq(Byte, Vec<u8>): because Bytes impls PartialEq with Vec<u8>, we can compare them directly.
1 parent 2963c8d commit 5cef3b6

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

rust/impls/src/postgres_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ mod tests {
829829

830830
// Construct entry that's for a field that's the maximum size of a non-"large_object" object
831831
let large_value = vec![0u8; MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN];
832-
let kv = KeyValue { key: "k1".into(), version: 0, value: Bytes::from(large_value) };
832+
let kv = KeyValue { key: "k1".into(), version: 0, value: Bytes::from(large_value.clone()) };
833833

834834
{
835835
let store =
@@ -868,7 +868,7 @@ mod tests {
868868
resp_kv.value.len(),
869869
MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN
870870
);
871-
assert!(resp_kv.value.iter().all(|&b| b == 0));
871+
assert_eq!(resp_kv.value, large_value);
872872

873873
store
874874
.delete(

rust/server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ fn main() {
4242
eprintln!("Failed to load configuration: {}", e);
4343
std::process::exit(-1);
4444
});
45-
let vss_service_config = match &config.max_request_body_size {
46-
Some(size) => match VssServiceConfig::new(*size) {
45+
let vss_service_config = match config.max_request_body_size {
46+
Some(size) => match VssServiceConfig::new(size) {
4747
Ok(config) => config,
4848
Err(e) => {
4949
eprintln!("Configuration validation error: {}", e);

rust/server/src/util/config.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,23 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
106106
None => (None, None),
107107
};
108108

109-
let bind_address_env = read_env(BIND_ADDR_VAR)?
110-
.map(|addr| {
111-
addr.parse().map_err(|e| {
112-
format!("Unable to parse the bind address environment variable: {}", e)
113-
})
114-
})
115-
.transpose()?;
109+
let bind_address_env = read_env(BIND_ADDR_VAR)?;
116110
let bind_address = read_config(
117111
bind_address_env,
118112
bind_address_config,
119113
"VSS server bind address",
120114
BIND_ADDR_VAR,
121115
)?;
122116

117+
let max_request_body_size_env = read_env(MAX_REQUEST_BODY_SIZE_VAR)?
118+
.map(|mrbs| {
119+
mrbs.parse::<usize>().map_err(|e| {
120+
format!("Unable to parse the maximum request body size environment variable: {}", e)
121+
})
122+
})
123+
.transpose()?;
124+
let max_request_body_size = max_request_body_size_env.or(max_request_body_size_config);
125+
123126
let log_level_env: Option<LevelFilter> = read_env(LOG_LEVEL_VAR)?
124127
.map(|level_str| {
125128
level_str
@@ -148,15 +151,6 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
148151
let log_file_config: Option<PathBuf> = log_config.and_then(|config| config.file);
149152
let log_file = log_file_env.or(log_file_config).unwrap_or(PathBuf::from("vss.log"));
150153

151-
let max_request_body_size_env = read_env(MAX_REQUEST_BODY_SIZE_VAR)?
152-
.map(|mrbs| {
153-
mrbs.parse::<usize>().map_err(|e| {
154-
format!("Unable to parse the maximum request body size environment variable: {}", e)
155-
})
156-
})
157-
.transpose()?;
158-
let max_request_body_size = max_request_body_size_env.or(max_request_body_size_config);
159-
160154
let rsa_pem_env = read_env(JWT_RSA_PEM_VAR)?;
161155
let rsa_pem = rsa_pem_env.or(jwt_auth_config.and_then(|config| config.rsa_pem));
162156

rust/server/src/vss_service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ async fn handle_request<
221221
return Ok(Response::builder()
222222
.status(StatusCode::PAYLOAD_TOO_LARGE)
223223
.body(Full::new(Bytes::from("Request body too large")))
224+
// unwrap safety: body only errors when previous chained calls failed.
224225
.unwrap());
225226
},
226227
};

0 commit comments

Comments
 (0)