Skip to content

Guard CFF2 BLEND operator against empty argument stack - #222

Open
scadastrangelove wants to merge 1 commit into
harfbuzz:mainfrom
scadastrangelove:fix/cff2-blend-argstack-underflow
Open

Guard CFF2 BLEND operator against empty argument stack#222
scadastrangelove wants to merge 1 commit into
harfbuzz:mainfrom
scadastrangelove:fix/cff2-blend-argstack-underflow

Conversation

@scadastrangelove

Copy link
Copy Markdown

Closes #218.

operator::BLEND => {
    ctx.had_blend = true;

    if p.stack.is_empty() {
        return Err(CFFError::InvalidArgumentsStackLength);
    }

    let n = u16::try_num_from(p.stack.pop())
        ...

Mirrors the existing VS_INDEX guard immediately above it (if p.stack.len() != 1 { return Err(...) }) and reuses the existing CFFError::InvalidArgumentsStackLength variant — no new
error type needed.

Testing

  • Full suite green: cargo test --all-features --release — 148/149 (the one failure,
    font_collection_num_fonts_overflow_2, is pre-existing and reproduces identically on
    unmodified main, unrelated to this change).
  • Verified the attached reproducer panics on unpatched main and returns a clean None with
    this patch.

Discovered by the rust-in-peace security pipeline.

VS_INDEX checks p.stack.len() != 1 before its pop; BLEND popped
unconditionally to read its operand count, hitting the mandatory
slice bounds check once len wraps to usize::MAX -- same root cause
as harfbuzz#80 (fixed by f28f7a5), which only touched cff1.rs's seac path
and left cff2.rs's BLEND operator unguarded.

Discovered by the rust-in-peace security pipeline
(https://github.com/scadastrangelove/rust-in-peace/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CFF2 BLEND operator can pop from an empty argument stack — same root cause as #80, unpatched in CFF2

1 participant