clipboard: clear the offer before examining a new copy; text/image size caps
Clipboard.cs:111-114 nulls LastClipboardData and LastDragDropFile before it looks at the new clipboard, so a branch that decides not to share leaves nothing for a peer to pull. FormHelper.cs:204-210 and :287 refuse text over 20 MB and images over 50 MB at the reader. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
4181bb273f
commit
1365db96e4
2 files changed
+18
-5
No files matched your search
@@ -120,6 +120,10 @@ public final class PasteboardWatcher: @unchecked Sendable {
|
||||
// and all — so the wire form is built here rather than in the codec.
|
||||
text.html = html.hasPrefix("Version:") ? html : ClipboardCodec.cfHTML(wrapping: html)
|
||||
}
|
||||
// `FormHelper.cs:204-210`: too much text is not shared at all, measured
|
||||
// on the tagged blob before compression.
|
||||
let length = (text.plain?.count ?? 0) + (text.rtf?.count ?? 0) + (text.html?.count ?? 0)
|
||||
guard length <= ClipboardCodec.maxTextLength else { return ClipboardText() }
|
||||
return text
|
||||
}
|
||||
|
||||
@@ -131,12 +135,17 @@ public final class PasteboardWatcher: @unchecked Sendable {
|
||||
return (text?.isEmpty ?? true) ? nil : text
|
||||
}
|
||||
|
||||
/// PNG if the pasteboard has it, else TIFF re-encoded. `FormHelper.cs:287`
|
||||
/// refuses an image over 50 MB rather than sharing it.
|
||||
private static func readPNG(_ pasteboard: NSPasteboard) -> Data? {
|
||||
if let png = pasteboard.data(forType: .png), !png.isEmpty { return png }
|
||||
guard let tiff = pasteboard.data(forType: .tiff),
|
||||
let rep = NSBitmapImageRep(data: tiff),
|
||||
let png = rep.representation(using: .png, properties: [:])
|
||||
else { return nil }
|
||||
var png = pasteboard.data(forType: .png)
|
||||
if png?.isEmpty ?? true {
|
||||
guard let tiff = pasteboard.data(forType: .tiff),
|
||||
let rep = NSBitmapImageRep(data: tiff)
|
||||
else { return nil }
|
||||
png = rep.representation(using: .png, properties: [:])
|
||||
}
|
||||
guard let png, !png.isEmpty, png.count <= ClipboardCodec.maxImageSize else { return nil }
|
||||
return png
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,10 @@ public final class ClipboardBridge {
|
||||
/// the peer can pull.
|
||||
public func localCopy(_ content: ClipboardContent, now: TimeInterval) -> [ClipboardAction] {
|
||||
guard shareClipboard else { return [] }
|
||||
// `Clipboard.cs:111-114`: whatever was on offer is forgotten before the
|
||||
// new clipboard contents are looked at, so a branch that decides not to
|
||||
// share leaves nothing behind for a peer to pull.
|
||||
bulk.serve(nil)
|
||||
switch content {
|
||||
case .file(let url):
|
||||
return localFile(url)
|
||||
|
||||
Reference in new issue
Block a user