Skip to content

Add per-MIME clipboard size limits and OOM protection#3571

Merged
hluk merged 3 commits into
masterfrom
fix/clipboard-monitor-bad-alloc-crash
Apr 25, 2026
Merged

Add per-MIME clipboard size limits and OOM protection#3571
hluk merged 3 commits into
masterfrom
fix/clipboard-monitor-bad-alloc-crash

Conversation

@hluk
Copy link
Copy Markdown
Owner

@hluk hluk commented Apr 21, 2026

Add clipboard_mime_size_limit config option and
COPYQ_CLIPBOARD_MIME_SIZE_LIMIT env var. Rules are semicolon-separated
pattern:limit pairs (e.g. text/html.:0;.:100M). Default: .*:100M.

Catch std::bad_alloc in ClipboardDataGuard leaf methods (data, text,
urls, imageData, getUtf8Data). Guard parseByteSize against qint64
overflow. Enforce size limits in leaf methods so fallback paths in
getImageData are also protected.

Assisted-by: Claude (Anthropic)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 95.52469% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.41%. Comparing base (1767abe) to head (2f3d945).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/tests/tests.cpp 84.76% 16 Missing ⚠️
src/common/clipboarddataguard.cpp 89.76% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3571      +/-   ##
==========================================
+ Coverage   74.24%   74.41%   +0.16%     
==========================================
  Files         252      253       +1     
  Lines       37498    37818     +320     
  Branches     5077     5105      +28     
==========================================
+ Hits        27841    28141     +300     
- Misses       9657     9677      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch 6 times, most recently from 1911973 to 197657b Compare April 22, 2026 08:41
@hluk hluk changed the title Fix clipboard monitor crash after screen lock/unlock on Wayland Support human-readable size suffixes in clipboard_mime_size_limit Apr 22, 2026
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch from 197657b to db5fae8 Compare April 22, 2026 08:44
@hluk hluk changed the title Support human-readable size suffixes in clipboard_mime_size_limit Add per-MIME clipboard size limits and catch OOM in clipboard access Apr 22, 2026
@hluk hluk requested a review from Copilot April 22, 2026 09:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable per-MIME clipboard size limits (via config and env var) and hardens clipboard cloning against allocation failures so clipboard monitoring can continue under extreme clipboard contents.

Changes:

  • Introduces clipboard_mime_size_limit config option and COPYQ_CLIPBOARD_MIME_SIZE_LIMIT env var parsing/caching for per-MIME byte limits.
  • Adds std::bad_alloc handling around several QMimeData accessors used during clipboard cloning.
  • Adds tests and FAQ documentation for the new size-limit feature.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/common/clipboarddataguard.cpp Implements rule parsing/caching, size enforcement, and OOM catches for clipboard reads.
src/common/appconfig.h Adds Config::clipboard_mime_size_limit option definition.
src/gui/configurationmanager.cpp Registers the new config option with the configuration system.
src/app/clipboardserver.cpp Bumps a config generation counter to invalidate cached rules on reload.
src/tests/tests_other.cpp Adds tests covering env-var and config-based size-limit behavior.
src/tests/tests.h Declares new test slots.
docs/faq.rst Documents how to configure clipboard size limits.
.gitignore Ignores compile_commands.json.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/common/clipboarddataguard.cpp Outdated
Comment thread src/common/clipboarddataguard.cpp
Comment thread src/common/clipboarddataguard.cpp
Comment thread src/common/clipboarddataguard.cpp
Comment thread src/common/clipboarddataguard.cpp Outdated
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch from db5fae8 to 53709e6 Compare April 22, 2026 12:57
@hluk hluk changed the title Add per-MIME clipboard size limits and catch OOM in clipboard access Add per-MIME clipboard size limits and OOM protection Apr 22, 2026
Add clipboard_mime_size_limit config option and
COPYQ_CLIPBOARD_MIME_SIZE_LIMIT env var. Rules are semicolon-separated
pattern:limit pairs (e.g. text/html.*:0;.*:100M). Default: .*:100M.

Catch std::bad_alloc in ClipboardDataGuard leaf methods (data, text,
urls, imageData, getUtf8Data). Guard parseByteSize against qint64
overflow. Enforce size limits in leaf methods so fallback paths in
getImageData are also protected.

Assisted-by: Claude (Anthropic)
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch 9 times, most recently from 0560b1c to 95ebee4 Compare April 23, 2026 16:38
@hluk hluk requested a review from Copilot April 24, 2026 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tests/tests.cpp Outdated
Comment thread src/tests/tests_other.cpp Outdated
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch 2 times, most recently from 6f2bc64 to 55475cb Compare April 24, 2026 12:06
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch 2 times, most recently from c9c8196 to e3e371e Compare April 24, 2026 14:14
Split tests into per-group classes with a lightweight aggregator that
dispatches to them. Adding a new test group is a single macro line.

Individual tests are now discoverable via -datatags and selectable with
group:tag syntax. Remove the old PLUGINS:<regex> argument. Update CI
workflows and documentation to use the new syntax.

CLI examples:
  ./copyq-tests testCore
  ./copyq-tests "testCore:configPath"
  ./copyq-tests -datatags
  COPYQ_TESTS_FILTER=clipboard ./copyq-tests

Assisted-by: Claude (Anthropic)
@hluk hluk force-pushed the fix/clipboard-monitor-bad-alloc-crash branch from 6696e39 to 0dc5908 Compare April 25, 2026 06:21
@hluk hluk merged commit b7d4ea6 into master Apr 25, 2026
15 of 16 checks passed
@hluk hluk deleted the fix/clipboard-monitor-bad-alloc-crash branch May 16, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants