Skip to content

macOS port: fix freezes, unclickable controls and a crash found while running the lattice-attack dialogs - #5

Open
mmarusiak wants to merge 5 commits into
wroclaw-tech:mainfrom
mmarusiak:macos-fixes
Open

mmarusiak wants to merge 5 commits into
wroclaw-tech:mainfrom
mmarusiak:macos-fixes

Conversation

@mmarusiak

Copy link
Copy Markdown

Summary

While using the macOS build for a cryptanalysis course (lab on brute force and RSA lattice attacks) I ran the
Factorization, Prime Number Generation, Factoring Knowing a Fraction of p, Attack on Stereotyped Messages,
Attack on Small Secret Exponents (Bloemer/May) and Brute-Force Analysis dialogs and hit several problems.
This PR fixes them; each fix is a separate commit.

Fixes

  1. Deadlock in the factorisation progress dialog (kernel.cpp, wnd.cpp, internal.h).
    CDlgProgressFactorisation::OnInitDialog spins in Sleep(2) on the main thread until all worker threads have
    registered, but a worker that already holds the dialog lock waits in RunOnMainThread (via SetTimer ->
    IsWindow) for the main thread. Sleep() now processes pending events when called on the main thread.
    "Complete factorization into primes" froze the whole app before.
  2. Stack overflow when pasting a long modulus (controls.cpp, SetControlText).
    Both branches called SetValue, so setting an edit to its current text still fired a change event. Handlers that
    update sibling edits (stereotyped-message dialog) recursed until the stack overflowed (SIGSEGV in
    OnChangeEditplainfull). Only notify when the text really changes.
  3. Group boxes swallowed mouse clicks (controls.cpp).
    Win32 group boxes are transparent to the mouse, but the rc files often declare them after the controls they
    enclose. A wxStaticBox created later sat on top, making edits and radio buttons (e.g. the ciphertext field of the
    stereotyped-message dialog) unclickable. Group boxes are now kept at the bottom of the z-order.
  4. Document tabs could not be selected or closed (docview.cpp).
    The wxAuiTabCtrl id falls into the command id range, so UpdateCommandUI treated it as a menu command without a
    handler and disabled it (MFC auto menu enable). The tab control and notebook are now skipped.
  5. Bloemer/May dialog erased N, e and d while typing (RSABloemerMayDlg.cpp).
    checkStartButton updates the bit length and delta edits, whose change handlers clear N, e and d (meant for user
    edits). With change notifications on programmatic updates, typing a digit in N wiped it. The handlers now ignore
    updates made by the dialog itself.

Testing

Built on macOS (arm64, Homebrew wxwidgets@3.2 openssl@3 gmp ninja cmake) and exercised manually:
factorisation of an 18-digit number, prime generation up to 10^700, all three lattice-attack dialogs (results
cross-checked against an independent implementation), AES/IDEA brute-force analysis with unknown key bits, and
opening, switching and closing several document tabs. No automated tests were added.

Known issue (not fixed here)

Generating two random primes of about 1200 digits in "Prime Number Generation" crashes with a segfault in
GeneratePrimes::MillerRabinTest (null Big in compare, worker thread). Ranges up to 10^700 work. I did not find
the cause and do not know whether it is port-specific.

A worker holding a lock while waiting in RunOnMainThread deadlocked with the main
thread spinning in a Sleep loop (CDlgProgressFactorisation::OnInitDialog), freezing
the factorisation dialog. Sleep() now processes pending events on the main thread.
SetControlText called SetValue in both branches, so setting an edit to its current
text still fired a change event. Handlers that update sibling edits (e.g. the
stereotyped-message dialog) then recursed until the stack overflowed when a long
modulus was pasted.
Win32 group boxes are transparent to the mouse, but rc files often declare them after
the controls they enclose. A wxStaticBox created later sat on top and swallowed
clicks, making edits such as the ciphertext field of the stereotyped-message dialog
unclickable.
…mmand

The AUI tab control and notebook get wx ids that fall into the command id range, so
UpdateCommandUI treated them as menu commands without a handler and disabled them
(MFC auto-menu-enable), leaving document tabs unclickable and not closable.
…programmatic updates

checkStartButton updates the bit length and delta edits, whose change handlers clear
N, e and d (meant for user edits). With change notifications on programmatic updates
this erased the modulus as soon as a digit was typed. Skip those handlers while the
dialog updates the fields itself.
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.

1 participant