Skip to content

DoubleWeaveFields and DoubleWeaveFrames request out-of-bounds child frame at output tail #52

Description

@msg7086

Analysis attribution: This issue analysis was created by Gemini 3.7 Flash.
The GitHub user who submits this issue does not claim authorship of the analysis.

Finding

  • Finding ID: F24-doubleweave-tail-frame-out-of-bounds
  • Status: Reproduced defect
  • Severity: Medium
  • Affected component: DoubleWeaveFields and DoubleWeaveFrames
  • Source location: avs_core/filters/field.cpp:866-879 and 930-940

Summary

DoubleWeaveFields and DoubleWeaveFrames advertise output frame counts up to their tail frames, but unconditionally request frame n + 1 or (n + 1) >> 1 from the child clip, which requests 1 frame past the end of the child clip when evaluating the final output frame.

Affected Code

PVideoFrame DoubleWeaveFields::GetFrame(int n, IScriptEnvironment* env)
{
  PVideoFrame a = child->GetFrame(n, env);
  PVideoFrame b = child->GetFrame(n+1, env);

  PVideoFrame result = env->NewVideoFrameP(vi, &a);

  const bool parity = child->GetParity(n);

  copy_field(result, a, vi.IsYUV() || vi.IsYUVA(), vi.IsPlanarRGB() || vi.IsPlanarRGBA(), parity, env);
  copy_field(result, b, vi.IsYUV() || vi.IsYUVA(), vi.IsPlanarRGB() || vi.IsPlanarRGBA(), !parity, env);

  return result;
}
PVideoFrame DoubleWeaveFrames::GetFrame(int n, IScriptEnvironment* env)
{
  if (!(n&1))
  {
    return child->GetFrame(n>>1, env);
  }
  else {
    PVideoFrame a = child->GetFrame(n>>1, env);
    PVideoFrame b = child->GetFrame((n+1)>>1, env);
    bool parity = this->GetParity(n);
...

Correct Behavior

Clamp the second child frame index to the child clip's last available frame (std::min(n + 1, child->GetVideoInfo().num_frames - 1) or std::min((n + 1) >> 1, child->GetVideoInfo().num_frames - 1)) so that evaluating the last advertised frame does not exceed child bounds.

Reproduction

Construct DoubleWeaveFields or DoubleWeaveFrames on a finite child clip of length $N$, then call GetFrame(vi.num_frames - 1).

Observed Result

observed: filter requests frame N from child clip, throwing out_of_range or crashing on finite sources
expected: filter successfully serves the last frame without requesting past-end frames from child

Impact

Consumers requesting the final advertised frame of a double-weave stream fail with out-of-range exceptions when backed by strict or finite frame sources.

Validation Criteria

Evaluating GetFrame(vi.num_frames - 1) succeeds and strictly requests only child frames in the range [0, child_num_frames - 1].

Version and Environment

  • AviSynthPlus revision: 80da03a5ee437c2b103dbebc9fab43480a9d97c6
  • Platform and compiler: Linux x86_64 / Windows x64 GCC/MSVC
  • CPU features used: host-default build.

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