Add span-based I/O wrappers as core/fxcrt/span_io.h [pdfium : main]

0 views
Skip to first unread message

Tom Sepez (Gerrit)

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

Tom Sepez voted and added 3 comments

Votes added by Tom Sepez

Commit-Queue+1

3 comments

File core/fxcrt/span_io.h
Line 95, Patchset 13: if (!::ReadFile(hFile, s.data(), static_cast<DWORD>(s.size_bytes()),
Tom Sepez . resolved

`static_cast<DWORD>` could silently truncate if `s.size_bytes()` exceeds 4GB (i.e. larger than `MAXDWORD`). Consider using `pdfium::base::checked_cast<DWORD>` (from `core/fxcrt/numerics/safe_conversions.h`) to fail safely if such large buffers are ever passed. The same applies to `WriteFile` below.

Line 61, Patchset 13: if (bytes_read <= 0) {
Tom Sepez . resolved

If `s` is empty (i.e. `s.size_bytes() == 0`), `read()` will return 0, which triggers this `<= 0` check and returns an empty span. This works, but passing a null pointer (which a default-constructed span might have) to `read()` can technically result in `EFAULT` on some OSs. You might want to add an early return if `s.empty()`. The same applies to `spanwrite`, `ReadFile`, and `WriteFile`.

Line 38, Patchset 13:// Bounds-checked writes from a container into a file. Returns whether the
Tom Sepez . resolved

The comment says "Returns whether the entire container was successfully written." which implies a boolean return type, but the function returns `size_t` representing the number of elements written. The same documentation mismatch exists for the POSIX and Windows overloads below.

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: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d
Gerrit-Change-Number: 149030
Gerrit-PatchSet: 14
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, 02 Jun 2026 18:11:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Tom Sepez (Gerrit)

unread,
Jun 2, 2026, 5:41:13 PM (2 days ago) Jun 2
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: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d
Gerrit-Change-Number: 149030
Gerrit-PatchSet: 17
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, 02 Jun 2026 21:41:11 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Lei Zhang (Gerrit)

unread,
Jun 3, 2026, 8:33:56 PM (20 hours ago) Jun 3
to Tom Sepez, Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
Attention needed from Tom Sepez

Lei Zhang added 3 comments

Commit Message
Line 22, Patchset 17 (Latest):Note that CFX_FileAccess_Posix may have fixed a latent error
Lei Zhang . unresolved

"CFX_FileAccess_Posix changes"

File core/fxge/cfx_folderfontinfo.cpp
Line 217, Patchset 17 (Latest): char buffer[12];
Lei Zhang . unresolved

Can be uint8_t?

File testing/image_diff/image_diff.cpp
Line 95, Patchset 17 (Latest): auto read_span = fxcrt::spanread(pdfium::span(buf), f);
Lei Zhang . unresolved

Explicit span construction not needed?

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: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d
    Gerrit-Change-Number: 149030
    Gerrit-PatchSet: 17
    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: Thu, 04 Jun 2026 00:33:53 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Lei Zhang (Gerrit)

    unread,
    Jun 3, 2026, 8:59:22 PM (19 hours ago) Jun 3
    to Tom Sepez, Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
    Attention needed from Tom Sepez

    Lei Zhang added 7 comments

    File core/fxcrt/span_io.h
    Line 103, Patchset 17 (Latest):inline pdfium::span<T> spanread(Container&& dst, HANDLE hFile) {
    Lei Zhang . unresolved

    More hHandles.

    Line 31, Patchset 17 (Latest):inline pdfium::span<T> spanread(Container&& dst, FILE* pFile) {
    Lei Zhang . unresolved

    C++ style naming.

    Line 8, Patchset 17 (Latest):#include <stdio.h>
    Lei Zhang . unresolved

    Newline after.

    File core/fxcrt/span_io_unittest.cpp
    Line 26, Patchset 17 (Latest): FILE* f = tmpfile();
    Lei Zhang . unresolved

    Add scopers to wrap all the different types of temp file creation + cleanup.

    Line 151, Patchset 17 (Latest): HANDLE hFile = ::CreateFileW(
    Lei Zhang . unresolved

    hHey!

    File testing/helpers/write.cc
    Line 511, Patchset 17 (Latest): auto src_span =
    Lei Zhang . unresolved

    Create closer to where used?

    Line 601, Patchset 17 (Latest): auto src_span = pdfium::span(
    Lei Zhang . unresolved

    This didn't need UNSAFE_TODO()?

    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: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d
    Gerrit-Change-Number: 149030
    Gerrit-PatchSet: 17
    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: Thu, 04 Jun 2026 00:59:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Tom Sepez (Gerrit)

    unread,
    3:38 PM (1 hour ago) 3:38 PM
    to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
    Attention needed from Lei Zhang

    Tom Sepez voted and added 10 comments

    Votes added by Tom Sepez

    Commit-Queue+1

    10 comments

    Commit Message
    Line 22, Patchset 17:Note that CFX_FileAccess_Posix may have fixed a latent error
    Lei Zhang . resolved

    "CFX_FileAccess_Posix changes"

    Tom Sepez

    Done

    File core/fxcrt/span_io.h
    Line 103, Patchset 17:inline pdfium::span<T> spanread(Container&& dst, HANDLE hFile) {
    Lei Zhang . resolved

    More hHandles.

    Tom Sepez

    Done

    Line 31, Patchset 17:inline pdfium::span<T> spanread(Container&& dst, FILE* pFile) {
    Lei Zhang . resolved

    C++ style naming.

    Tom Sepez

    Done

    Line 8, Patchset 17:#include <stdio.h>
    Lei Zhang . resolved

    Newline after.

    Tom Sepez

    Done

    File core/fxcrt/span_io_unittest.cpp
    Line 26, Patchset 17: FILE* f = tmpfile();
    Lei Zhang . resolved

    Add scopers to wrap all the different types of temp file creation + cleanup.

    Tom Sepez

    Done

    Line 151, Patchset 17: HANDLE hFile = ::CreateFileW(
    Lei Zhang . resolved

    hHey!

    Tom Sepez

    Done

    File core/fxge/cfx_folderfontinfo.cpp
    Line 217, Patchset 17: char buffer[12];
    Lei Zhang . resolved

    Can be uint8_t?

    Tom Sepez

    Done

    File testing/helpers/write.cc
    Line 511, Patchset 17: auto src_span =
    Lei Zhang . resolved

    Create closer to where used?

    Tom Sepez

    Nah, create after we just validated out_len.

    Line 601, Patchset 17: auto src_span = pdfium::span(
    Lei Zhang . resolved

    This didn't need UNSAFE_TODO()?

    Tom Sepez

    I think the test directory is exempted by the config file. added anyway.

    File testing/image_diff/image_diff.cpp
    Line 95, Patchset 17: auto read_span = fxcrt::spanread(pdfium::span(buf), f);
    Lei Zhang . resolved

    Explicit span construction not needed?

    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: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d
      Gerrit-Change-Number: 149030
      Gerrit-PatchSet: 25
      Gerrit-Attention: Lei Zhang <the...@chromium.org>
      Gerrit-Comment-Date: Thu, 04 Jun 2026 19:38:16 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages