Skip to content

[AUD-009][High] Reject unreconstructable DWT dimensions and use synthesis filters #307

Description

@gabrielsantosphilips

Audit finding

  • ID: AUD-009
  • Status: Verified defect
  • Severity: High
  • Confidence: High
  • Audited revision: 2f479320d805a1f9f35ebe4afaaeeded48913a94

Problem

The DWT requires positive N and Levels but does not require N to be divisible by 2^Levels. It also exposes synthesis filters but SynthesisStep() reads the analysis filters instead.

Source:

{
static_assert(std::is_floating_point_v<T>, "DiscreteWaveletTransform supports floating-point types only");
static_assert(N > 0, "DiscreteWaveletTransform N must be > 0");
static_assert(Levels > 0, "DiscreteWaveletTransform Levels must be > 0");
static_assert(Taps >= 2, "DiscreteWaveletTransform Taps must be >= 2");
and
{
T sumA{ 0 };
T sumD{ 0 };
for (std::size_t i = 0; i < half; ++i)
{
std::size_t fIdx = (n + outLen - 2 * i) % outLen;
if (fIdx < Taps)
{
sumA += filters.lowAnalysis[fIdx] * ca[i];
sumD += filters.highAnalysis[fIdx] * cd[i];
}
}
out[n] = sumA + sumD;
}
}
template<typename T, std::size_t N, std::size_t Levels, std::size_t Taps>
OPTIMIZE_FOR_SPEED void DiscreteWaveletTransform<T, N, Levels, Taps>::Forward(const Signal& x, Signal& coeffs)
{
coeffs.clear();
coeffs.resize(N, T{ 0 });
for (std::size_t i = 0; i < N; ++i)

Reproduction

DiscreteWaveletTransform<float, 3, 1, 2> constructs and performs forward transform, then inverse reconstruction aborts on an internal bounded-vector access.

Acceptance criteria

  • Enforce compatible N/Levels at compile time.
  • Check exact runtime signal and coefficient sizes.
  • Use the supplied synthesis filters, or narrow the API to orthogonal analysis-only coefficients.
  • Add invalid-dimension compile checks and independent biorthogonal reconstruction tests.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions