Skip to content

Debug touch feedback can crash when native touches array is shorter than gesture count #168

Description

@thomasttvo

Summary

PR #152 review flagged a pre-existing debug-mode crash: the pinch debug path reads both touch entries without checking the actual native touch array length. I checked current master and PR #165 (thomas/pre-existing-fixes-v2), and both still have the same unguarded access.

Source review thread: #152 (comment)

Current code

Both origin/master and PR #165 still do:

const { touches } = gestureResponderEvent.nativeEvent;

setDebugPoints([
  {
    x: touches[0].pageX - originalPageX,
    y: touches[0].pageY - originalPageY,
  },
  {
    x: touches[1].pageX - originalPageX,
    y: touches[1].pageY - originalPageY,
  },
  zoomCenter,
  ...points,
]);

Impact

This is limited to debug mode (debug={true}), but a gesture event where gestureState.numberActiveTouches === 2 while nativeEvent.touches.length < 2 can throw TypeError: Cannot read properties of undefined and terminate the gesture/debug session.

Suggested fix

Guard before reading touch entries:

if (touches.length < 2) return;

Then keep the existing setDebugPoints behavior for valid two-touch events.

Triage note

This is not covered by PR #165 or current master as of PR #152 HEAD 5fee673 / PR #165 HEAD c2796dc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions