mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Bound exec-server JSON-RPC decoding complexity (#33013)
## Why Compact JSON arrays can expand into millions of heap values during decoding, and duplicate object keys make a message ambiguous. ## What changed - Limit exec-server JSON-RPC messages to 256K JSON values and reject duplicate object keys. - Cap `fs/read_directory` results and retained `process/read` output at 50,000 entries or chunks so locally produced responses remain within the decoder budget. ## Testing Add coverage for all JSON-RPC variants, large scalar payloads, duplicate keys, compact array amplification, and retained process output at the chunk limit. GitOrigin-RevId: e31d1f25ab0a7e2272015c98174fd2b7cdd669d7
This commit is contained in:
1 parent
d7ba5ff955
commit
325cf16194
5 files changed
+380
-5
No files matched your search
@@ -11,6 +11,7 @@ use crate::ExecutorFileSystem;
|
||||
use crate::RemoveOptions;
|
||||
use crate::file_read::FileReadHandleManager;
|
||||
use crate::local_file_system::LocalFileSystem;
|
||||
use crate::protocol::FS_READ_DIRECTORY_METHOD;
|
||||
use crate::protocol::FS_WRITE_FILE_METHOD;
|
||||
use crate::protocol::FsCanonicalizeParams;
|
||||
use crate::protocol::FsCanonicalizeResponse;
|
||||
@@ -42,6 +43,9 @@ use crate::rpc::invalid_request;
|
||||
use crate::rpc::not_found;
|
||||
|
||||
const MAX_FILE_READ_HANDLE_ID_BYTES: usize = 32;
|
||||
// Each read-directory entry needs four JSON values. Keep same-version
|
||||
// producers comfortably below the shared 256K-value decoder budget.
|
||||
const MAX_READ_DIRECTORY_ENTRIES: usize = 50_000;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct FileSystemHandler {
|
||||
@@ -189,7 +193,14 @@ impl FileSystemHandler {
|
||||
.file_system
|
||||
.read_directory(¶ms.path, params.sandbox.as_ref())
|
||||
.await
|
||||
.map_err(map_fs_error)?
|
||||
.map_err(map_fs_error)?;
|
||||
let entry_count = entries.len();
|
||||
if entry_count > MAX_READ_DIRECTORY_ENTRIES {
|
||||
return Err(internal_error(format!(
|
||||
"{FS_READ_DIRECTORY_METHOD} returned {entry_count} entries; limit is {MAX_READ_DIRECTORY_ENTRIES}"
|
||||
)));
|
||||
}
|
||||
let entries = entries
|
||||
.into_iter()
|
||||
.map(|entry| FsReadDirectoryEntry {
|
||||
file_name: entry.file_name,
|
||||
|
||||
Reference in new issue
Block a user