{"record":{"id":"4659b72a8578efc4","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-4659b7","errorCode":null,"errorMessage":"分享数据大小或格式无效","messagePattern":"分享数据大小或格式无效","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/session_share.rs","lineNumber":137,"sourceCode":"    if encrypted.get(\"v\").and_then(Value::as_u64) != Some(1) {\n        bail!(\"不支持此分享的数据格式\");\n    }\n    let decode = |field: &str| -> anyhow::Result<Vec<u8>> {\n        let value = encrypted\n            .get(field)\n            .and_then(Value::as_str)\n            .with_context(|| format!(\"分享数据缺少 {field}\"))?;\n        base64::engine::general_purpose::URL_SAFE_NO_PAD\n            .decode(value)\n            .with_context(|| format!(\"分享数据 {field} 无效\"))\n    };\n    let key = base64::engine::general_purpose::URL_SAFE_NO_PAD\n        .decode(key_value)\n        .context(\"分享链接解密密钥无效\")?;\n    let iv = decode(\"iv\")?;\n    let ciphertext = decode(\"ciphertext\")?;\n    if key.len() != 32 || iv.len() != 12 || ciphertext.len() > MAX_ROLLOUT_BYTES + 16 {\n        bail!(\"分享数据大小或格式无效\");\n    }\n    let cipher = Aes256Gcm::new_from_slice(&key).context(\"创建会话解密器失败\")?;\n    cipher\n        .decrypt(Nonce::from_slice(&iv), ciphertext.as_ref())\n        .map_err(|_| anyhow::anyhow!(\"分享会话解密失败\"))\n}\n\npub fn import_rollout_file(home: &Path, source_path: &Path) -> anyhow::Result<Value> {\n    let bytes = fs::read(source_path)\n        .with_context(|| format!(\"读取会话文件失败：{}\", source_path.display()))?;\n    if bytes.len() > MAX_ROLLOUT_BYTES {\n        bail!(\"会话文件超过导入大小限制\");\n    }\n    let content = String::from_utf8(bytes).context(\"会话文件不是有效的 UTF-8\")?;\n    if let Ok(payload) = serde_json::from_str::<Value>(&content)\n        && payload.get(\"kind\").and_then(Value::as_str) == Some(\"codex-rollout\")\n    {\n        return import_rollout(home, &payload);","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/session_share.rs#L119-L155","documentation":"decrypt_shared_payload enforces size constraints: a 32-byte AES-256 key, a 12-byte GCM IV, and ciphertext no larger than MAX_ROLLOUT_BYTES + 16 (16 MiB + GCM tag). Any violation aborts before decryption.","triggerScenarios":"The decoded key is not 32 bytes, the decoded iv is not 12 bytes, or the ciphertext exceeds 16 MiB + 16 — e.g. a truncated base64 fragment key, a wrong IV encoding, or an oversized shared session.","commonSituations":"URL fragment truncated so the base64 key is incomplete; wrong base64 variant (padded vs URL-safe-no-pad); sharing a rollout larger than the 16 MiB cap; hand-assembled envelopes.","solutions":["Copy the share link intact so the full base64 key (32 bytes decoded) is present","Re-share the session if it exceeds the 16 MiB rollout cap (trim or split the session)","Use URL_SAFE_NO_PAD base64 consistently when constructing share envelopes","Check that iv is a 12-byte value encoded as base64"],"exampleFix":"// before\nlet key = general_purpose::STANDARD.decode(key_value)?; // padded std b64 mismatches\n// after\nlet key = general_purpose::URL_SAFE_NO_PAD.decode(key_value)?; // matches expected encoding","handlingStrategy":"validation","validationCode":"fn share_envelope_sizes_ok(key_value: &str, encrypted: &serde_json::Value, max_cipher: usize) -> bool {\n    use base64::Engine;\n    let key_ok = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(key_value).map(|k| k.len() == 32).unwrap_or(false);\n    let iv_ok = encrypted.get(\"iv\").and_then(|v| v.as_str()).map(|s| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(s).map(|i| i.len() == 12).unwrap_or(false)).unwrap_or(false);\n    let ct_ok = encrypted.get(\"ciphertext\").and_then(|v| v.as_str()).map(|s| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(s).map(|c| c.len() <= max_cipher).unwrap_or(false)).unwrap_or(false);\n    key_ok && iv_ok && ct_ok\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Preserve the complete URL fragment so the 32-byte key decodes fully","Use URL_SAFE_NO_PAD base64 for all envelope fields","Keep shared rollouts under the 16 MiB cap; trim large sessions before sharing"],"tags":["encryption","payload-size","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}