Skip to content

Regression: fgetcsv() separator argument — empty/null accepted, Zend ValueError/TypeError (ext/standard/file.c) #12018

Description

@PurHur

Category

stdlib · php-src-strict

Problem

fgetcsv() $separator validation is too permissive. Zend rejects invalid separators; VM parses rows anyway.

$separator Zend VM
'' (empty string) ValueError: … must be a single character parses ['a','b'] ❌
null TypeError (string expected) parses uncaught ❌
',' success success ✓

Distinct from #8975 (enum case operands) and #9303 (escape/enclosure parsing).

php-src reference

PHP implementation today

  • ext/standard/fgetcsv.php, ext/standard/VmCsv.php (or equivalent CSV helper)

Repro

  • test/repro/maintainer_gap_fgetcsv_separator_validation.php (empty '')
  • test/repro/maintainer_gap_fgetcsv_null_separator_typeerror.php (null)
./script/docker-exec.sh -- php test/repro/maintainer_gap_fgetcsv_separator_validation.php      # Zend: ok
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_fgetcsv_separator_validation.php  # VM: fail
./script/docker-exec.sh -- php test/repro/maintainer_gap_fgetcsv_null_separator_typeerror.php
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_fgetcsv_null_separator_typeerror.php

Implementation hints (PHP-in-PHP)

  • Reuse VmString::coerceStringBuiltinArg / strict arg guards: separator must be exactly one byte
  • Reject null with TypeError before IO
  • Mirror str_getcsv() separator rules for consistency

Done when

  • Both repro scripts print ok on VM
  • Valid fgetcsv($fp, 0, ',', '"', '\\') unchanged
  • Compliance .phpt guard committed

Refs #1492, #8975, #9303.

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 26, 2026
  2. PurHur commented on Jun 26, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #12018, #12017)

  3. PurHur commented on Jun 26, 2026

    @PurHur
    OwnerAuthor

    Merged via #12022. VM + JIT compliance + AOT compile-only guard green in Docker.

  4. PurHur commented on Jul 5, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-a — named separator: null misbinds to length slot (compileCallArgs null fast path skips nameSlot); reopening binding aspect of #12018.

  5. PurHur commented on Jul 5, 2026

    @PurHur
    OwnerAuthor

    Merged via #16327.

    Fix: compileCallArgSends() registers callArgNameSlot before null-literal fast-path TYPE_ARG_SEND, so fgetcsv($fp, separator: null) binds to $separator not $length.

    Verify:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_fgetcsv_null_separator_typeerror.php'
    

    → ok (ValueError on argument #3).

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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions