w3c / w3c/webcodecs

Should spec validate buffer size by codedSize when constructing VideoFrame from a buffer

Open
#516 1 comment 0 reactions 1 assignee View on GitHub

@padenot is already working on this.

Since Mar 16, 2023.

need-definition
Dominant language
HTML
Stars
1.3k
Forks
194
Avg merge
1d 13h
Merged PRs (30d)
3

Description

When constructing VideoFrame from the buffer, the buffer size (a.k.a. data.byteLength) must be bigger than or equal to the allocationSize of result of Compute Layout and Allocation Size, in step 11. However, if the (codedWidth, codedHeight) is (3, 3) and visibleRect’s (x, y, width, height) is (0, 0, 1, 1), giving a buffer with 2 x 2 x 4 size that contains 2-pixel width, 2-pixel height data in RGBA format can pass that check. Is this expected? Is it allowed to construct a 3 x 3 RGBA buffer with 1 x 1 visible rect by a 2 x 2 RGBA buffer data?

FYI, Chromium refuses to construct a VideoFrame in this case:

Uncaught TypeError: Failed to construct 'VideoFrame': data is not large enough.

// test case
let data = new Uint8Array([
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
]);
let frame = new VideoFrame(data, {
  timestamp: 10,
  codedWidth: 3,
  codedHeight: 3,
  visibleRect: { x: 0, y: 0, width: 1, height: 1 },
  format: "RGBA",
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.