Skip to content

fix: Round 8 polish — encrypt wipe, update worker leak, CLI, DPR change#79

Merged
nelsonduarte merged 7 commits into
mainfrom
fix/round8-polish-rebased
Jun 5, 2026
Merged

fix: Round 8 polish — encrypt wipe, update worker leak, CLI, DPR change#79
nelsonduarte merged 7 commits into
mainfrom
fix/round8-polish-rebased

Conversation

@nelsonduarte
Copy link
Copy Markdown
Owner

Summary

Closes 7 selective findings from audit Round 8: 2 HIGH, 3 MEDIUM, 2 BONUS polish items.

Note: This PR supersedes #77, which was rebased onto current main after the #72/#78 squashes. Same 7 commits, cherry-picked onto fresh main.

Fixes

  • R8-H1 wipe encrypt passwords (app/tools/encrypt.py) — QLineEdits persisted password text. New _clear_password_fields invoked from try/finally in _run().
  • R8-H2 update worker leak (app/window.py) — _update_worker QObject never deleteLater()'d. New _release_update_worker helper.
  • R8-M1 CLI argparse (pdfapps.py) — -h/--help/--version now work; accepts multiple PDF paths via nargs="*".
  • R8/D1 DPR change handler (app/viewer/canvas.py, app/editor/canvas.py) — canvases now react to QWindow.screenChanged and invalidate cached pixmaps.
  • Dead _update_ready signal removed (app/window.py).

Bonus fixes

  • Watermark encrypted PDF (app/tools/watermark.py) — _prompt_watermark_password handles encrypted watermarks gracefully.
  • _populate_toc graceful failure (app/viewer/panel.py) — wrapped in try/except + logging.warning.

Tests

10 new tests in tests/test_round8_fixes.py covering encrypt wipe, update worker release, CLI argparse, DPR handlers, watermark prompt, and TOC failure.

Final

Supersedes #77.

QLineEdit text for owner/user/decrypt passwords persisted in memory
for the entire session. Now cleared via try/finally in _run() to align
with the broader wipe_pdf_password() pattern.

Addresses R8-H1.
The _update_worker QObject lived for the lifetime of the application
because only _update_thread.deleteLater was wired. Now released in
_on_update_found() via _release_update_worker() and called defensively
from closeEvent.

Also removes the dead _update_ready signal: it was declared at the
class level and connected to _notify_update, but never emitted — the
actual update notification path is via _update_worker.done.

Addresses R8-H2 and R8 dead-code finding.
Previously only sys.argv[1] was opened, so multi-file "Open With" or
drag-and-drop of N>1 PDFs onto the executable silently dropped every
file after the first. -h / --help was treated as an invalid path and
the app launched into the welcome screen.

Now uses argparse: accepts multiple PDF paths (each opens in its own
tab via _load_and_track), and exposes standard --help / --version
flags that exit before QApplication is constructed.

Addresses R8-M1.
Both viewer/canvas.py and editor/canvas.py read devicePixelRatioF()
only inside _schedule_visible(). Without a screenChanged handler,
moving the window between 100% and 200% monitors (or changing the
DPR of an active monitor via Windows Display Settings) left every
visible page blurry until the next zoom interaction.

New showEvent override connects to window.windowHandle().screenChanged
and invalidates cached pixmaps on DPR change, then re-queues the
visible range. The connect is guarded against duplicate handlers on
re-show / tab switch.

Addresses R8/D1.
PdfReader(wm_path) raised PdfReadError cryptically when the watermark
PDF was itself encrypted (rare but observed with corporate stamp
PDFs). Now a dedicated _prompt_watermark_password() helper prompts
for the watermark's password before pre-flight and the worker
decrypts the second reader with it, kept separate from
self._pdf_password so source and watermark credentials don't mix.

Addresses R8 bonus #6.
A malformed outline (cyclic refs, bad page indexes, unexpected entry
shape) could raise mid-build and leave the TOC panel in an
inconsistent state — half-populated and surfaced as a stack trace.
Now the failure is logged via logging.warning and the TOC tree is
reset to an empty / hidden state so the rest of the viewer stays
usable.

Addresses R8 bonus #7.
10 new tests guard the PR-C wiring against silent regressions:

- encrypt._clear_password_fields() + try/finally hookup
- _release_update_worker helper + _update_ready signal removal
- argparse CLI (multi-PDF, --help, --version) — also exercises
  the subprocess version/help flags end-to-end
- screenChanged DPR handler on viewer + editor canvases
- watermark encrypted PDF prompt path
- _populate_toc try/except + logging
@nelsonduarte nelsonduarte merged commit a53b1eb into main Jun 5, 2026
2 checks passed
@nelsonduarte nelsonduarte deleted the fix/round8-polish-rebased branch June 5, 2026 17:45
import sys
from pathlib import Path

import pytest
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