{"record":{"id":"d8f83ec2507dc203","repo":"herdrdev/herdr","slug":"encoded-clipboard-image-exceeds-protocol-limit","errorCode":null,"errorMessage":"encoded clipboard image exceeds protocol limit","messagePattern":"encoded clipboard image exceeds protocol limit","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"warning","filePath":"src/platform/windows/clipboard_image.rs","lineNumber":317,"sourceCode":"}\n\nimpl LimitedWriter {\n    fn new(limit: usize) -> Self {\n        Self {\n            bytes: Vec::new(),\n            limit,\n        }\n    }\n\n    fn into_inner(self) -> Vec<u8> {\n        self.bytes\n    }\n}\n\nimpl io::Write for LimitedWriter {\n    fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {\n        if bytes.len() > self.limit.saturating_sub(self.bytes.len()) {\n            return Err(io::Error::new(\n                io::ErrorKind::FileTooLarge,\n                \"encoded clipboard image exceeds protocol limit\",\n            ));\n        }\n        self.bytes.extend_from_slice(bytes);\n        Ok(bytes.len())\n    }\n\n    fn flush(&mut self) -> io::Result<()> {\n        Ok(())\n    }\n}\n\nfn read_u16_le(bytes: &[u8], offset: usize) -> Option<u16> {\n    Some(u16::from_le_bytes(\n        bytes.get(offset..offset + 2)?.try_into().ok()?,\n    ))\n}","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/herdrdev/herdr/blob/f457cff4f2648eee85d176f8a41861241d4e8428/src/platform/windows/clipboard_image.rs#L299-L335","documentation":"A clipboard image being encoded for the remote/protocol path exceeded the hard byte cap enforced by LimitedWriter. The writer counts appended bytes and refuses any write that would push the encoded payload past the configured protocol limit, failing with ErrorKind::FileTooLarge. This protects the wire protocol from oversized image frames.","triggerScenarios":"Calling the Windows clipboard image encode path with a large screen capture or image paste while a client/protocol limit is configured, so that the encoded PNG/data bytes exceed LimitedWriter's limit during io::Write::write.","commonSituations":"Copying full-screen or multi-monitor screenshots, high-DPI captures, or very large images on Windows and attempting to sync them through Herdr's protocol; smaller images work but large ones fail deterministically.","solutions":["Reduce the clipboard image size before encoding (crop, downscale, or lower resolution) so the encoded bytes fit under the protocol limit","Compress/re-encode the image (e.g. PNG optimization or lossy format) to shrink payload size","Check what limit is configured for the protocol path and raise it if your deployment can tolerate larger frames","Skip image sync for oversized payloads and fall back to text-only clipboard transfer"],"exampleFix":"// before: copying a full 4K screenshot fails during encode\nlet mut w = LimitedWriter::new(limit);\nimage.write_encoder().encode(&mut w)?; // FileTooLarge\n\n// after: downscale before encoding so payload fits\nlet scaled = image.resize_to_fit(max_dim);\nlet mut w = LimitedWriter::new(limit);\nscaled.write_encoder().encode(&mut w)?;","handlingStrategy":"validation","validationCode":"// Before syncing clipboard, estimate encoded size and skip if too large\nlet encoded_len = estimate_encoded_len(&image);\nif encoded_len > protocol_limit { skip_image_sync_or_downscale(&image); }","typeGuard":null,"tryCatchPattern":"match encode_clipboard_image(img, limit) {\n    Ok(bytes) => send(bytes),\n    Err(e) if e.kind() == std::io::ErrorKind::FileTooLarge => { /* downscale and retry, or send text-only */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Downscale or crop large screenshots before clipboard sync","Know the configured protocol image limit before pasting images","Treat oversized images as skip-with-warning, not fatal"],"tags":["clipboard","windows","image-encoding","size-limit","protocol"],"backgroundTag":"payload-too-large","analyzedSha":"f457cff4f2648eee85d176f8a41861241d4e8428","analyzedAt":"2026-08-28T15:41:09.197Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}