8000 Harden argument validation across MEX commands (complex, sparse, fractional, out-of-range input) · Issue #21 · ptahmose/MEXlibCZI · GitHub
[go: up one dir, main page]

Skip to content

Harden argument validation across MEX commands (complex, sparse, fractional, out-of-range in 8F11 put) #21

Closed

Description

@ptahmose

Background

While reviewing PR #20 (QuerySubBlockDirectory), automated review showed that argument validation in the existing MEX commands is not strict enough. The new command was hardened on its own. The shared helpers and the older commands were deliberately left unchanged to keep that PR focused.

Problems

  • Complex arrays are not rejected. They reach mxGetDoubles and similar calls, which abort the whole MEX call instead of raising a catchable error. Fixing this needs a new pfn_IsComplex in the app-extension API (MATLAB, Octave and the function table).
  • Sparse arrays are not rejected consistently by the existing commands.
  • Fractional values: CArgsUtils::TryGetInt32 rounds floating-point input via lrint. For example, 0.5 or 1.7 is silently accepted as an integer.
  • Out-of-range values: floating-point input at or beyond the int32 limits is not rejected. For example, single(2147483648) is accepted because of float rounding at INT_MAX.
  • Unsupported classes: TryGetInt32 does not handle the logical class.
  • Helpers built on TryGetInt32 inherit these problems, including TryGetIntRect.

Proposed work

  1. Add pfn_IsComplex to the app API, and reject complex input wherever numeric arguments are read.
  2. Make the shared integer helpers strict. They should reject fractional, non-finite and out-of-range values, and handle the logical class explicitly.
  3. Apply sparse and complex checks consistently in every command's CheckArguments.
  4. Add MATLAB and Octave tests for each rejection case.

Reference

QuerySubBlockDirectory (PR #20) already contains the stricter validation, e.g. TryGetIntegralInt32 in lib/src/functions/func_querysubblockdirectory.cpp. It can serve as a model, or be refactored into the shared helpers.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0