Skip to content

Layout: a heading level past the fifth clamps to H6, and so does a negative one #514

Open

Description

@Tim81

HeadingRenderer maps a heading level to a structure type through a switch whose default arm is
H6. Levels past the fifth clamp to it silently, and so does every negative level.

// src/VellumPdf.Layout/Rendering/HeadingRenderer.cs:36
private static string HeadingStructType(int level) => level switch
{
    0 => "H1", 1 => "H2", 2 => "H3", 3 => "H4", 4 => "H5",
    _ => "H6",
};

Heading.Level is public int Level { get; init; } with no validation anywhere.

Measured

Reported by VellumPdfShowcase against the published 2.3.2 package, on net10.0 Windows x64 Release,
reading the emitted structure type:

Level structure type
0 /H1
1 /H2
5 /H6
6 /H6
7 /H6
100 /H6
int.MaxValue /H6
-5 /H6

Level is 0-based, so the first two rows are the intended mapping rather than an off-by-one. The
last row is the one their report does not name: the default arm catches negatives as well as
overflow, so a heading the caller numbered -5 is tagged as a sixth-level heading.

What the standard permits

ISO 14289-1:2014, 7.4.3:

If a PDF that contains the tags H1, H2, H3, H4, H5, and H6 (in any permissible sequence) requires
more headings, tags numbered from H7 upward (without limit) may be defined and used.

The same clause requires the tag be the letter H followed by Arabic numerals with no intervening
whitespace and no numerical separator, and forbids any other numbering system. So there is no
ceiling to respect, and a negative level has no valid tag at all.

Clause 7.4.2 constrains the sequence rather than the ceiling: if any heading tag is used, H1 shall
be first, and a descending sequence shall not skip a level. That is a document-level property this
library cannot enforce from a single heading, so it belongs in the member's documentation as a
caller obligation.

Why it matters beyond a wrong tag

A consumer is paying for it now. VellumPdfShowcase keeps a MaxHeadingLevel of 5 for this
reason alone, so that the level it displays and the structure the file carries agree. The cap exists
because the library clamps, not because the format has a limit.

Assistive technology reads the structure type. A document whose seventh-level headings all arrive as
H6 has lost its outline depth with no error and no diagnostic.

Scope

Considered and rejected

Refusing a level above 5 instead of honouring it. It leaves the showcase needing its cap, which is
the cost this issue exists to remove, and 7.4.3 is explicit that H7 upward is permitted.

Found while planning 2.3.3, from the showcase's re-measurement of the published package. The
negative-level row and the clause reading are mine.

Activity

  1. added this to the v2.3.3 — Hardening milestone on Sep 12, 2026
  2. added
    bug
    on Sep 12, 2026
  3. Tim81 commented on Nov 18, 2026

    @Tim81
    OwnerAuthor

    The 2026-11-16 handbook research confirms the issue and adds a decision for v2.4. One correction to how it was
    summarised elsewhere.

    Levels are zero-based. HeadingRenderer.cs:36-44:

    0 => "H1",
    1 => "H2",
    2 => "H3",
    3 => "H4",
    4 => "H5",
    _ => "H6",

    So level 5 maps to H6, which is correct. The clamp begins at level 6, which should be H7; level 6 and every higher
    level, and every negative level, map to H6. The research's observation (Level = 6 gave H6 directly after H1)
    is consistent with this table, and the table in this issue already has the same rows. I could not find an
    off-by-one in either; where a summary says "level 5" or "level 6" is the first wrong one, the code says level 6.

    ISO 14289-1 7.4.3 allows H7 and higher (H followed by Arabic numerals), so the fix is H{level + 1} for any
    level at or above 0, as this issue proposes.

    Change for v2.4 against the scope above: a negative level, and a skipped level (7.4.2: if any heading tag is
    used, H1 is first and a descending sequence does not skip a level; the research's ua-headingskip file, H1 then
    H3, failed veraPDF 7.4.2-1 and saved without a report), are reported through the diagnostics channel (#607).
    Strict mode (opt-in) refuses them. Refusal by default is 3.0 (#484), so the "refuse a negative level through
    LayoutValidation" line moves to strict mode. The H7+ mapping itself changes bytes only for levels that are
    wrong today.

  4. Tim81 commented on Nov 29, 2026

    @Tim81
    OwnerAuthor

    The ISO audit (docs/conformance-v2.4.md) has skipped tests that wait on this issue; the fix removes their skip and makes them pass.

    • Iso14289_1_7_4_3_AHeadingPastTheSixthLevelIsAnH7 (group G3)
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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions