Skip to content

check-package.mjs rejects valid npm tarballs when Windows tar emits CRLF #32

Closed

Description

@ShawnSiao

Summary

scripts/check-package.mjs rejects a valid npm tarball on Windows when the system tar command emits CRLF line endings for tar -tvzf.

The validation uses a multiline regular expression directly on the complete listing. In JavaScript, both CR and LF are line terminators for multiline anchors, so ^ can match between the \r and \n. The following \n is then tested as if it were the first character of a new line and triggers the non-regular-entry error.

Affected version and environment

  • Released package: @openai/[email protected]
  • Confirmed still present on current main at f22d4a36f26d16287bcdfd707b369116e02a08c3
  • Microsoft Windows NT 10.0.19045.0
  • PowerShell 7.6.3
  • Node.js 24.18.0
  • pnpm 11.17.0
  • bsdtar 3.5.2 / libarchive 3.5.2

Steps to reproduce

From the repository root:

cd sdk/typescript
corepack pnpm install --frozen-lockfile
corepack pnpm run build
corepack pnpm pack --pack-destination ../../dist
node scripts/check-package.mjs ../../dist/openai-codex-security-0.1.1.tgz

Observed error:

Error: npm tarball contains a non-regular entry (symbolic or hard link, device, or pipe).
    at scripts/check-package.mjs:185

I then captured the exact tar --ignore-zeros -tvzf output and checked every non-empty line. The generated archive contained 178 entries, and every listing line began with - or d; there were no links, devices, or pipes.

The package installation smoke test also passed:

Validated installed @openai/[email protected]: public import, CLI, and 94 bundled plugin files.

A minimal diagnostic using the same listing demonstrated the false match:

/^[^d-]/mu.exec(listing) matches the LF in the first CRLF sequence.

Expected behavior

A valid npm tarball containing only regular files and allowed directories should pass check-package.mjs regardless of whether the local tar command emits LF or CRLF.

Actual behavior

The validator reports a non-regular tar entry before the later code normalizes the same listing with split(/\r?\n/u).

Impact

Windows contributors using a CRLF-emitting tar implementation cannot run the repository's package-boundary validation locally, even though the generated package is valid and installable.

Relevant code

  • Current check:
    const listing = tar(["-tvzf", archive], "utf8");
    if (/^[^d-]/mu.test(listing)) {
    throw new Error(
    "npm tarball contains a non-regular entry (symbolic or hard link, device, or pipe).",
    );
    }
    const listingLines = listing.split(/\r?\n/u).filter(Boolean);
    if (
  • The code immediately below already creates normalized listingLines:
    }
    const listingLines = listing.split(/\r?\n/u).filter(Boolean);
    if (
    listingLines.length !== entries.length ||
    listingLines.some(
    (line, index) => line.startsWith("d") !== entries[index].endsWith("/"),
    )
    ) {
    throw new Error("npm tarball contains an invalid tar entry.");
    }
    const launcherPermissions =

PR #3 introduced the package-boundary checker and validated a Windows CI configuration, but its patch and review discussion do not cover a tar implementation that emits CRLF for verbose listings.

Suggested direction

Normalize the listing before checking entry types and reuse the normalized lines for both validations. For example:

const listingLines = listing.split(/\r?\n/u).filter(Boolean);
if (
  listingLines.some(
    (line) => !line.startsWith("d") && !line.startsWith("-"),
  )
) {
  throw new Error(
    "npm tarball contains a non-regular entry (symbolic or hard link, device, or pipe).",
  );
}

A focused regression test can pass a CRLF-formatted verbose listing with only regular files and assert that it is accepted.

Activity

  1. zhuyuy commented on Jul 29, 2026

    @zhuyuy

    I independently reproduced this on Windows NT 10.0.26200.0, PowerShell 7.6.3, code page 936, Node.js 22.22.1, and the project-declared pnpm 11.9.0, against f22d4a36f26d16287bcdfd707b369116e02a08c3.

    The real build and pack completed, but the baseline package check reported a non-regular entry. The same archive contained 179 verbose-listing entries, all starting with d or -; the multiline regex matched the LF inside the first CRLF sequence.

    I tested a minimal implementation reference that creates listingLines first and performs the entry-type check on those normalized lines:

    zhuyuy@6c1cc7f

    Validation with Node.js 24.15.0 and pnpm 11.9.0 passed type checking, the full formatting check, build, and pack. The fixed checker then reported:

    Validated ...openai-codex-security-0.1.1.tgz: 179 entries.
    

    For this focused validation I passed plugin-files.json explicitly so the unrelated install smoke was not rerun; I am not claiming that smoke as part of this result. Sharing the fork commit as an implementation reference because external PRs cannot be imported into the canonical source.

  2. added
    bug
    good first issue
    on Aug 3, 2026
  3. added
    platform:windows
    priority:p2
    on Aug 15, 2026
  4. rohanpoudel2 commented on Aug 21, 2026

    @rohanpoudel2
    Contributor

    Fixed by #436, which parses native tar listings by complete lines, accepts both LF and CRLF, and continues rejecting non-regular archive entries.

  5. ShawnSiao commented on Aug 23, 2026

    @ShawnSiao
    Author

    I verified the fix in npm's current latest package,
    @openai/[email protected],
    on Windows.

    Release evidence:

    • Published: 2026-08-23 02:58:33 UTC
    • npm gitHead: e71fefc0918d918fb5b79486d0d626d5ec2ea2f3
    • PR #436 merge commit:
      17614f7765e75acc8878a747d42228c6e8ec9f18
    • The PR merge commit is an ancestor of the package gitHead.
    • The downloaded tarball's recomputed SHA-512 matched the npm registry
      integrity value.

    Environment:

    • Windows NT 10.0.19045.0
    • PowerShell 7.6.5
    • Code page 65001
    • Node.js 24.18.0
    • bsdtar 3.5.2

    Focused validation command:

    $package = '<local-validation-dir>\openai-codex-security-0.1.17.tgz'
    node sdk/typescript/scripts/check-package.mjs $package sdk/typescript/plugin-files.json

    The checker and plugin-files.json used for this command were taken from the
    package gitHead shown above.

    Result:

    Validated ...openai-codex-security-0.1.17.tgz: 263 entries.
    

    The command exited with status 0, and the original CRLF tar-listing false
    positive did not reproduce. This was the focused package check only; I did not
    rerun the install smoke or the full test suite for this release validation.

  6. mldangelo-oai commented on Aug 31, 2026

    @mldangelo-oai
    Collaborator

    Thanks for reporting this. I believe this is resolved by #436, which fixes CRLF handling in tar listings. Please feel free to reopen if you still run into it on the latest version.

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

    buggood first issueplatform:windowspriority:p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions