Replace FX_Random_MT_.* functions with FX_Random class [pdfium : main]

0 views
Skip to first unread message

Lei Zhang (Gerrit)

unread,
Feb 20, 2026, 2:09:27 PM (2 days ago) Feb 20
to Andy Phan, Lei Zhang, Pdfium LUCI CQ, pdfium-...@googlegroups.com
Attention needed from Andy Phan

Lei Zhang voted and added 2 comments

Votes added by Lei Zhang

Code-Review+1

2 comments

File core/fpdfapi/parser/cpdf_security_handler.cpp
Line 704, Patchset 12 (Latest): FX_Random::Fill(pdfium::span_from_ref(random_value));
Lei Zhang . unresolved

Existing: Just fill the 4 bytes of `buf` directly?

File core/fxcrt/fx_random.cpp
Line 115, Patchset 12 (Latest): // MT_M - `kN` underflows, but this is safe because unsigned underflow is
Lei Zhang . unresolved

Wrap this entire snippet in backticks?

Open in Gerrit

Related details

Attention is currently required from:
  • Andy Phan
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: Ia91391d8f6d586d469679d6701d9196f3ea4911e
Gerrit-Change-Number: 143451
Gerrit-PatchSet: 12
Gerrit-Owner: Andy Phan <andy...@chromium.org>
Gerrit-Reviewer: Andy Phan <andy...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Attention: Andy Phan <andy...@chromium.org>
Gerrit-Comment-Date: Fri, 20 Feb 2026 19:09:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Andy Phan (Gerrit)

unread,
Feb 20, 2026, 2:50:04 PM (2 days ago) Feb 20
to Lei Zhang, Pdfium LUCI CQ, pdfium-...@googlegroups.com

Andy Phan added 2 comments

File core/fpdfapi/parser/cpdf_security_handler.cpp
Line 704, Patchset 12: FX_Random::Fill(pdfium::span_from_ref(random_value));
Lei Zhang . resolved

Existing: Just fill the 4 bytes of `buf` directly?

Andy Phan

Done with fxcrt::reinterpret_span<>()

File core/fxcrt/fx_random.cpp
Line 115, Patchset 12: // MT_M - `kN` underflows, but this is safe because unsigned underflow is
Lei Zhang . resolved

Wrap this entire snippet in backticks?

Andy Phan

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: Ia91391d8f6d586d469679d6701d9196f3ea4911e
    Gerrit-Change-Number: 143451
    Gerrit-PatchSet: 13
    Gerrit-Owner: Andy Phan <andy...@chromium.org>
    Gerrit-Reviewer: Andy Phan <andy...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-Comment-Date: Fri, 20 Feb 2026 19:50:00 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
    satisfied_requirement
    open
    diffy

    Pdfium LUCI CQ (Gerrit)

    unread,
    Feb 20, 2026, 5:24:17 PM (2 days ago) Feb 20
    to Andy Phan, Lei Zhang, pdfium-...@googlegroups.com

    Pdfium LUCI CQ submitted the change with unreviewed changes

    Unreviewed changes

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

    ```
    The name of the file: core/fxcrt/fx_random.cpp
    Insertions: 1, Deletions: 1.

    @@ -112,7 +112,7 @@
    for (; kk < kN - 1; kk++) {
    v = (context_.mt[kk] & MT_Upper_Mask) |
    (context_.mt[kk + 1] & MT_Lower_Mask);
    - // MT_M - `kN` underflows, but this is safe because unsigned underflow is
    + // `MT_M - kN` underflows, but this is safe because unsigned underflow is
    // well-defined.
    context_.mt[kk] = context_.mt[kk + (MT_M - kN)] ^ (v >> 1) ^ mag[v & 1];
    }
    ```
    ```
    The name of the file: core/fpdfapi/parser/cpdf_security_handler.cpp
    Insertions: 2, Deletions: 4.

    @@ -700,10 +700,8 @@

    // In ISO 32000 Supplement for ExtensionLevel 3, Algorithm 3.10 says bytes 12
    // to 15 should be random data.
    - uint32_t random_value;
    - FX_Random::Fill(pdfium::span_from_ref(random_value));
    - fxcrt::Copy(pdfium::byte_span_from_ref(random_value),
    - pdfium::span(buf).subspan<12, 4>());
    + FX_Random::Fill(
    + fxcrt::reinterpret_span<uint32_t>(pdfium::span(buf).subspan<12, 4>()));

    CRYPT_aes_context aes = {};
    CRYPT_AESSetKey(&aes, encrypt_key_);
    ```

    Change information

    Commit message:
    Replace FX_Random_MT_.* functions with FX_Random class

    Replace the legacy C-style FX_Random_MT_.* functions with FX_Random,
    which owns its own MTContext, removing the need for callers to manage
    opening and closing MTContexts.

    Also remove "MT" from the class name to be consistent with the file
    name.
    Change-Id: Ia91391d8f6d586d469679d6701d9196f3ea4911e
    Reviewed-by: Lei Zhang <the...@chromium.org>
    Commit-Queue: Andy Phan <andy...@chromium.org>
    Files:
    • M core/fpdfapi/edit/cpdf_creator.cpp
    • M core/fpdfapi/parser/cpdf_security_handler.cpp
    • M core/fxcrt/fx_random.cpp
    • M core/fxcrt/fx_random.h
    • M core/fxcrt/fx_random_unittest.cpp
    • M fxjs/xfa/cfxjse_formcalc_context.cpp
    Change size: M
    Delta: 6 files changed, 76 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: Ia91391d8f6d586d469679d6701d9196f3ea4911e
    Gerrit-Change-Number: 143451
    Gerrit-PatchSet: 14
    Gerrit-Owner: Andy Phan <andy...@chromium.org>
    Gerrit-Reviewer: Andy Phan <andy...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages