mirror of
https://github.com/codewhale-hq/Codewhale.git
synced 2026-11-09 01:49:49 -10:00
fix(plugins): give the plugin state file room, and derive its limit message
`MAX_PLUGIN_STATE_BYTES` was 1 MiB. A plugin state file that outgrew it made `load_state` fail with "plugin state … exceeds the 1 MiB limit", which turns every plugin into a load failure for that user with no way out short of deleting their state by hand. The ceiling is now 16 MiB. The read stays bounded: `file.take(MAX_PLUGIN_STATE_BYTES + 1)` caps it before the length check, so this raises the ceiling without ever reading an unbounded file. The refusal message now derives its number from the constant instead of restating "1 MiB", so the next change cannot leave the message lying. Found as uncommitted work in the shared checkout and landed under the Own everything in CW rule after it had been unchanged for 19 minutes. No test pins the old 1 MiB value. Verification: `rustfmt --check` passes on the file. A crate build was not run - the shared build lock was held by another session throughout the attempt - so CI is the verifier for compilation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1f40f4ba05
commit
1d4443510f
1 file changed
+4
-3
@@ -847,7 +847,7 @@ fn load_state(path: &Path) -> Result<PluginStateFile, String> {
|
||||
}
|
||||
|
||||
/// Maximum bytes read from the plugin state file.
|
||||
const MAX_PLUGIN_STATE_BYTES: u64 = 1024 * 1024;
|
||||
const MAX_PLUGIN_STATE_BYTES: u64 = 16 * 1024 * 1024;
|
||||
|
||||
fn load_state_unlocked(path: &Path) -> Result<PluginStateFile, String> {
|
||||
let Some(file) = open_existing_regular_file(path, false)? else {
|
||||
@@ -859,8 +859,9 @@ fn load_state_unlocked(path: &Path) -> Result<PluginStateFile, String> {
|
||||
.map_err(|e| format!("failed to read {}: {e}", path.display()))?;
|
||||
if raw.len() as u64 > MAX_PLUGIN_STATE_BYTES {
|
||||
return Err(format!(
|
||||
"plugin state {} exceeds the 1 MiB limit",
|
||||
path.display()
|
||||
"plugin state {} exceeds the {} MiB limit",
|
||||
path.display(),
|
||||
MAX_PLUGIN_STATE_BYTES / (1024 * 1024)
|
||||
));
|
||||
}
|
||||
let state: PluginStateFile = serde_json::from_str(&raw)
|
||||
|
||||
Reference in new issue
Block a user