Skip to content

Eliminate undefined or implementation-defined arithmetic in codec hot paths #8

Description

@audexdev

Summary

Several codec paths rely on signed overflow, implementation-defined narrowing, or unchecked shift counts when used with full-range int32_t inputs or malformed streams.

Affected areas

  • src/codec/simd/neon.cpp
  • src/codec/lac/decoder.cpp
  • src/codec/block/encoder.cpp
  • src/codec/block/decoder.cpp
  • src/codec/rice/rice.cpp
  • src/codec/lpc/lpc.cpp

Problem details

Known cases:

  • mid/side scalar encode computes l + r and l - r in int32_t
  • mid/side decode reconstructs with signed int32_t expressions
  • fixed/FIR residual and restore paths narrow unchecked int64_t values to int32_t
  • Rice::encode/decode accepts k >= 32, which is invalid for 32-bit shifts
  • LPC autocorrelation uses int64_t accumulation while public APIs accept arbitrary int32_t samples

Acceptance criteria

  • Use explicit widened arithmetic and range checks where required.
  • Reject or clamp malformed decode states consistently according to format rules.
  • Add sanitizer-backed tests for boundary values, including full-range int32_t synthetic inputs where applicable.
  • Add direct Rice tests for invalid k and k == 31 boundary behavior.

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

    bugSomething isn't workinghardeningInput validation and robustness hardening

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions