Refactor manual font table parsing in CFX_FolderFontInfo [pdfium : main]

0 views
Skip to first unread message

Tom Sepez (Gerrit)

unread,
Jun 22, 2026, 2:26:36 PM (3 days ago) Jun 22
to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
Attention needed from Lei Zhang

New activity on the change

Open in Gerrit

Related details

Attention is currently required from:
  • Lei Zhang
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pdfium
Gerrit-Branch: main
Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
Gerrit-Change-Number: 150410
Gerrit-PatchSet: 12
Gerrit-Owner: Tom Sepez <tse...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
Gerrit-Attention: Lei Zhang <the...@chromium.org>
Gerrit-Comment-Date: Mon, 22 Jun 2026 18:26:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Lei Zhang (Gerrit)

unread,
Jun 22, 2026, 6:44:12 PM (2 days ago) Jun 22
to Tom Sepez, Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
Attention needed from Tom Sepez

Lei Zhang added 9 comments

Commit Message
Line 12, Patchset 12 (Latest):parsing logic in `CFX_FolderFontInfo` when scanning system fonts and retrieving font data.
Lei Zhang . unresolved

wrap

File core/fxge/cfx_folderfontinfo.cpp
Line 179, Patchset 12 (Parent):
Lei Zhang . unresolved

Leave out random newline changes.

Line 208, Patchset 12 (Latest): uint32_t name_tag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
Lei Zhang . unresolved

Was fine as a constexpr value?

Line 209, Patchset 12 (Latest): auto loc = FindFontTable(tables.unsigned_span(), name_tag);
Lei Zhang . unresolved

Can't figure out what this is without looking it up. Same for other FindFontTable() callers.

Line 249, Patchset 12 (Latest): FX_SAFE_FILESIZE safe_os2_end = os2_loc->offset;
safe_os2_end += os2_loc->size;
if (safe_os2_end.IsValid() && safe_os2_end.ValueOrDie() <= filesize) {
auto os2_data = FixedSizeDataVector<uint8_t>::Uninit(os2_loc->size);
if (fseek(pFile, os2_loc->offset, SEEK_SET) >= 0 &&
fxcrt::spanread(os2_data.span(), pFile).size() == os2_loc->size) {
Lei Zhang . unresolved

Looks like lines 214-222. Refactor into helper?

Line 452, Patchset 12 (Parent): // TODO(tsepez): iterate over span.
Lei Zhang . unresolved

Did you want to fulfill this in FindFontTable()?

File core/fxge/fx_font.h
Line 99, Patchset 12 (Latest):pdfium::span<const uint8_t> GetFontTable(pdfium::span<const uint8_t> font_data,
Lei Zhang . unresolved

Only called from unit tests?

Line 95, Patchset 12 (Latest):std::optional<FontTableLocation> FindFontTable(
Lei Zhang . unresolved

Has no unit test coverage.

File core/fxge/fx_font.cpp
Line 171, Patchset 12 (Latest): size_t nTables = table_dir.size() / 16u;
Lei Zhang . unresolved

Might as well update C++ style since it's now in a different file and looks like new code.

Open in Gerrit

Related details

Attention is currently required from:
  • Tom Sepez
Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pdfium
    Gerrit-Branch: main
    Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
    Gerrit-Change-Number: 150410
    Gerrit-PatchSet: 12
    Gerrit-Owner: Tom Sepez <tse...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
    Gerrit-Attention: Tom Sepez <tse...@chromium.org>
    Gerrit-Comment-Date: Mon, 22 Jun 2026 22:44:06 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Tom Sepez (Gerrit)

    unread,
    Jun 23, 2026, 12:19:51 PM (2 days ago) Jun 23
    to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
    Attention needed from Lei Zhang

    Tom Sepez added 9 comments

    Commit Message
    Line 12, Patchset 12:parsing logic in `CFX_FolderFontInfo` when scanning system fonts and retrieving font data.
    Lei Zhang . resolved

    wrap

    Tom Sepez

    Done

    File core/fxge/cfx_folderfontinfo.cpp
    Lei Zhang . resolved

    Leave out random newline changes.

    Tom Sepez

    Done

    Line 208, Patchset 12: uint32_t name_tag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
    Lei Zhang . resolved

    Was fine as a constexpr value?

    Tom Sepez

    Done. Bud didn't need to be static.

    Line 209, Patchset 12: auto loc = FindFontTable(tables.unsigned_span(), name_tag);
    Lei Zhang . resolved

    Can't figure out what this is without looking it up. Same for other FindFontTable() callers.

    Tom Sepez

    Done

    Line 249, Patchset 12: FX_SAFE_FILESIZE safe_os2_end = os2_loc->offset;

    safe_os2_end += os2_loc->size;
    if (safe_os2_end.IsValid() && safe_os2_end.ValueOrDie() <= filesize) {
    auto os2_data = FixedSizeDataVector<uint8_t>::Uninit(os2_loc->size);
    if (fseek(pFile, os2_loc->offset, SEEK_SET) >= 0 &&
    fxcrt::spanread(os2_data.span(), pFile).size() == os2_loc->size) {
    Lei Zhang . resolved

    Looks like lines 214-222. Refactor into helper?

    Tom Sepez

    Done

    Line 452, Patchset 12 (Parent): // TODO(tsepez): iterate over span.
    Lei Zhang . resolved

    Did you want to fulfill this in FindFontTable()?

    Tom Sepez

    moved comment.

    File core/fxge/fx_font.h
    Line 99, Patchset 12:pdfium::span<const uint8_t> GetFontTable(pdfium::span<const uint8_t> font_data,
    Lei Zhang . resolved

    Only called from unit tests?

    Tom Sepez

    Done

    Line 95, Patchset 12:std::optional<FontTableLocation> FindFontTable(
    Lei Zhang . resolved

    Has no unit test coverage.

    Tom Sepez

    called from GetFontTable().

    Moved to tests.

    File core/fxge/fx_font.cpp
    Line 171, Patchset 12: size_t nTables = table_dir.size() / 16u;
    Lei Zhang . resolved

    Might as well update C++ style since it's now in a different file and looks like new code.

    Tom Sepez

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Lei Zhang
    Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: pdfium
      Gerrit-Branch: main
      Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
      Gerrit-Change-Number: 150410
      Gerrit-PatchSet: 17
      Gerrit-Attention: Lei Zhang <the...@chromium.org>
      Gerrit-Comment-Date: Tue, 23 Jun 2026 16:19:46 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Tom Sepez (Gerrit)

      unread,
      Jun 23, 2026, 12:29:12 PM (2 days ago) Jun 23
      to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
      Attention needed from Lei Zhang

      Tom Sepez voted and added 2 comments

      Votes added by Tom Sepez

      Commit-Queue+1

      2 comments

      File core/fxge/fx_font_unittest.cpp
      Line 18, Patchset 17:pdfium::span<const uint8_t> GetFontTable(pdfium::span<const uint8_t> font_data,
      Tom Sepez . resolved

      This helper duplicates logic found in non-test code (`cfx_folderfontinfo.cpp`):\n1. Parsing `nTables` from the font header.\n2. Checking table payload bounds against the data size (similar to `DataVectorAtLocation`).\n\nSince `CFX_FolderFontInfo` streams the font file from disk rather than loading it entirely into a memory span, we cannot easily share a common `GetFontTable` helper. However, we can avoid this duplication entirely by deleting this helper and testing `FindFontTableLocation` directly.

      Line 85, Patchset 17:TEST(FXFontTest, GetFontTable) {
      Tom Sepez . resolved

      If we drop the `GetFontTable` helper, we can simplify this test to evaluate `FindFontTableLocation` directly. We only need to pass a mock table directory array rather than a full TTF header:\n\n```cpp\nTEST(FXFontTest, FindFontTableLocation) {\n std::vector<uint8_t> table_dir = {\n // Table Directory Entry 1 ('head')\n 'h', 'e', 'a', 'd', 0x00, 0x00, 0x00, 0x00, // checksum\n 0x00, 0x00, 0x00, 0x2C, // offset = 44\n 0x00, 0x00, 0x00, 0x0A, // length = 10\n\n // Table Directory Entry 2 ('name')\n 'n', 'a', 'm', 'e', 0x00, 0x00, 0x00, 0x00, // checksum\n 0x00, 0x00, 0x00, 0x36, // offset = 54\n 0x00, 0x00, 0x00, 0x14, // length = 20\n };\n\n uint32_t head_tag = CFX_FontMapper::MakeTag('h', 'e', 'a', 'd');\n std::optional<FontTableLocation> head_loc = FindFontTableLocation(table_dir, head_tag);\n ASSERT_TRUE(head_loc.has_value());\n EXPECT_EQ(44u, head_loc->offset);\n EXPECT_EQ(10u, head_loc->size);\n\n // Add similar tests for the 'name' tag, 'gasp' tag (not found), and a truncated `table_dir` span.\n}\n```

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Lei Zhang
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: pdfium
      Gerrit-Branch: main
      Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
      Gerrit-Change-Number: 150410
      Gerrit-PatchSet: 18
      Gerrit-Owner: Tom Sepez <tse...@chromium.org>
      Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
      Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
      Gerrit-Attention: Lei Zhang <the...@chromium.org>
      Gerrit-Comment-Date: Tue, 23 Jun 2026 16:29:08 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Lei Zhang (Gerrit)

      unread,
      Jun 23, 2026, 4:17:28 PM (2 days ago) Jun 23
      to Tom Sepez, Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
      Attention needed from Tom Sepez

      Lei Zhang voted and added 2 comments

      Votes added by Lei Zhang

      Code-Review+1

      2 comments

      Commit Message
      Line 9, Patchset 18 (Latest):Introduce generic FindFontTableLocation() helper functions
      Lei Zhang . unresolved

      singular, also line 11.

      File core/fxge/cfx_folderfontinfo.cpp
      Line 225, Patchset 18 (Latest): constexpr uint32_t name_tag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
      Lei Zhang . unresolved

      Could have remained as kFoo.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Tom Sepez
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: pdfium
      Gerrit-Branch: main
      Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
      Gerrit-Change-Number: 150410
      Gerrit-PatchSet: 18
      Gerrit-Owner: Tom Sepez <tse...@chromium.org>
      Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
      Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
      Gerrit-Attention: Tom Sepez <tse...@chromium.org>
      Gerrit-Comment-Date: Tue, 23 Jun 2026 20:17:22 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Tom Sepez (Gerrit)

      unread,
      Jun 23, 2026, 4:22:38 PM (2 days ago) Jun 23
      to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com

      Tom Sepez voted and added 2 comments

      Votes added by Tom Sepez

      Commit-Queue+2

      2 comments

      Commit Message
      Line 9, Patchset 18:Introduce generic FindFontTableLocation() helper functions
      Lei Zhang . resolved

      singular, also line 11.

      Tom Sepez

      Done

      File core/fxge/cfx_folderfontinfo.cpp
      Line 225, Patchset 18: constexpr uint32_t name_tag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
      Lei Zhang . resolved

      Could have remained as kFoo.

      Tom Sepez

      Done

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
        Gerrit-Change-Number: 150410
        Gerrit-PatchSet: 20
        Gerrit-Comment-Date: Tue, 23 Jun 2026 20:22:31 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
        satisfied_requirement
        open
        diffy

        pdfium-scoped@luci-project-accounts.iam.gserviceaccount.com (Gerrit)

        unread,
        Jun 23, 2026, 5:20:14 PM (2 days ago) Jun 23
        to Tom Sepez, Lei Zhang, pdfium-...@googlegroups.com

        pdfium...@luci-project-accounts.iam.gserviceaccount.com submitted the change with unreviewed changes

        Unreviewed changes

        18 is the latest approved patch-set.
        The change was submitted with unreviewed changes in the following files:

        ```
        The name of the file: core/fxge/cfx_folderfontinfo.cpp
        Insertions: 2, Deletions: 2.

        @@ -222,9 +222,9 @@
        return;
        }

        - constexpr uint32_t name_tag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
        + constexpr uint32_t kNameTag = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
        std::optional<FontTableLocation> loc =
        - FindFontTableLocation(tables.unsigned_span(), name_tag);
        + FindFontTableLocation(tables.unsigned_span(), kNameTag);
        if (!loc) {
        return;
        }
        ```

        Change information

        Commit message:
        Refactor manual font table parsing in CFX_FolderFontInfo

        Introduce generic FindFontTableLocation() helper function
        in fx_font.h / fx_font.cpp to parse TrueType/OpenType table
        directories. This helper replaces duplicated and unsafe manual

        parsing logic in `CFX_FolderFontInfo` when scanning system fonts and
        retrieving font data.

        -- Remove one UNSAFE_TODO from the code.
        -- Back-fill unit tests for in `fx_font_unittest.cpp`.

        TAG=agy
        CONV=5b35af9a-640b-4f89-b828-d1d410d70943
        Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
        Commit-Queue: Tom Sepez <tse...@chromium.org>
        Reviewed-by: Lei Zhang <the...@chromium.org>
        Files:
        • M core/fxge/cfx_folderfontinfo.cpp
        • M core/fxge/cfx_folderfontinfo.h
        • M core/fxge/fx_font.cpp
        • M core/fxge/fx_font.h
        • M core/fxge/fx_font_unittest.cpp
        Change size: M
        Delta: 5 files changed, 183 insertions(+), 61 deletions(-)
        Branch: refs/heads/main
        Submit Requirements:
        • requirement satisfiedCode-Review: +1 by Lei Zhang
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I7a53b5bdf03e1e7c400377f514b1a760a4a2c9bf
        Gerrit-Change-Number: 150410
        Gerrit-PatchSet: 21
        Gerrit-Owner: Tom Sepez <tse...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
        open
        diffy
        satisfied_requirement
        Reply all
        Reply to author
        Forward
        0 new messages