Skip to content

Thread Safety: Fix TOCTOU race in Container.drawBorder() dimension access #254

Description

@sfloess

Part of #224: Improve Thread Safety in Component and Container

Scope

Address issue #4 from the parent issue:

Container.drawBorder() accesses width/height without lock (Container.java line 236)

  • Accesses width/height fields directly without acquiring renderLock
  • Early return check (line 237) reads dimensions without lock
  • TOCTOU race: dimensions could change between check and buffer writes
  • Could cause ArrayIndexOutOfBoundsException

Proposed Fix

Use getWidth()/getHeight() accessors or acquire renderLock before reading dimensions. Snapshot dimension values at the start of the method to prevent mid-method changes.

Acceptance Criteria

  • drawBorder() reads dimensions under lock or via synchronized accessors
  • No TOCTOU race between dimension check and buffer write
  • No ArrayIndexOutOfBoundsException possible from concurrent resize
  • Existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions