Review main Ready for review

97382[BUGFIX] Return blob from fetchOne() as string

Sebastian Mendel CR 0 V 0 Normal +76 −0 updated 11/19/26, 23:10

Commit message

DriverResult maps stream resources to strings so that pdo_* drivers
return blob columns the same way mysqli does. fetchOne() passes its
value through mapResourceToString(), but the method only converted
resources inside an array. On PostgreSQL, fetchOne() on a bytea column
therefore returned a stream, while the array fetches returned the
string.

mapResourceToString() now converts a resource passed as the record
itself. A functional test reads a blob column with fetchOne(),
fetchAssociative() and fetchFirstColumn().

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 4
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/82/97382/4 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/82/97382/4 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Issues 1

Files 2

Review log 1419

  1. Sebastian Mendel uploaded patch set 1 11/06/26, 07:24

  2. core-ci voted on patch set 1 V -1 11/06/26, 07:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113459

  3. Sebastian Mendel rebased onto patch set 2 V -1 11/06/26, 09:15

  4. core-ci voted on patch set 2 V +1 11/06/26, 09:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113475

  5. Sebastian Mendel rebased onto patch set 3 V +1 11/06/26, 10:09

  6. core-ci voted on patch set 3 V +1 11/06/26, 10:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113483

  7. Garvin Hicking commented on patch set 3 CR -1 11/06/26, 19:55

    The provided test does not turn red when the "is_resource" patch is removed. I think we need to have a test that fails first. That also would help me understand how this method is utilized in TYPO3 scope. (I think this fix is out of scope for 13.4)
  8. Sebastian Mendel commented on patch set 3 11/06/26, 22:27

    Reply

    Thanks for checking. The test only turns red on PostgreSQL: pdo_pgsql returns a `bytea` column as a stream, while sqlite, mysqli and pdo_mysql already return a string, so `mapResourceToString()` has nothing to map there. Command for both runs (PostgreSQL 15): `./Build/Scripts/runTests.sh -s functional -d postgres -i 15 -- --colors=never typo3/sysext/core/Tests/Functional/Database/Driver/DriverResultTest.php` Without the `is_resource()` branch: ``` PHPUnit 13.3.0 by Sebastian Bergmann and contributors. Runtime: PHP 8.5.12 Configuration: /home/cybot/projects/typo3-core/bugfix-fetchone-stream/Build/phpunit/FunctionalTests.xml F.. 3 / 3 (100%) Time: 00:00.864, Memory: 113.00 MB There was 1 failure: 1) TYPO3\CMS\Core\Tests\Functional\Database\Driver\DriverResultTest::fetchOneReturnsBlobColumnAsString Failed asserting that resource(5589) of type (stream) is identical to 's:5:"value";'. /home/cybot/projects/typo3-core/bugfix-fetchone-stream/typo3/sysext/core/Tests/Functional/Database/Driver/DriverResultTest.php:47 /home/cybot/projects/typo3-core/bugfix-fetchone-stream/bin/phpunit:122 FAILURES! Tests: 3, Assertions: 3, Failures: 1. Remove container for network "typo3-core-23576" ########################################################################### Result of functional Container runtime: docker Container suffix: 23576 PHP: 8.5 DBMS: postgres version 15 driver FAILURE ########################################################################### ``` With the patch: ``` PHPUnit 13.3.0 by Sebastian Bergmann and contributors. Runtime: PHP 8.5.12 Configuration: /home/cybot/projects/typo3-core/bugfix-fetchone-stream/Build/phpunit/FunctionalTests.xml ... 3 / 3 (100%) Time: 00:00.881, Memory: 113.00 MB OK (3 tests, 3 assertions) Remove container for network "typo3-core-11501" ########################################################################### Result of functional Container runtime: docker Container suffix: 11501 PHP: 8.5 DBMS: postgres version 15 driver SUCCESS ########################################################################### ``` PostgreSQL 17 (`-i 17`) gives the same result. On `-d sqlite`, `-d mariadb -a mysqli` and `-d mariadb -a pdo_mysql` the test is green with and without the fix. In core I found no `fetchOne()` that reads a blob value: of the 131 `fetchOne()` calls in `typo3/sysext/*/Classes`, five name a blob column (from the core `ext_tables.sql` files, plus the cache `content` column) in the 25 lines before the call, and all five fetch a `count()` or a non-blob column. That search only sees column names written as string literals near the call. The case comes from extensions that read a blob with `fetchOne()` on PostgreSQL: they get a stream, where `fetchAssociative()`, `fetchFirstColumn()` and every other platform return a string.
  9. Garvin Hicking commented on patch set 3 CR 0 11/06/26, 22:40

    Reply

    Ack! Will lift the -1 now, can check affer the weekend, but looks ok to me then!
  10. Simon Schaufelberger voted on patch set 3 CR +1 V +1 11/07/26, 10:26

  11. core-ci commented on patch set 3 11/09/26, 14:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113699

  12. Garvin Hicking commented on patch set 3 CR +1 V +1 11/09/26, 14:36

    Ran a nightly on it, lgtm
  13. Stefan Bürk commented on patch set 3 CR -1 11/19/26, 14:05

    Unresolved

    tmp -1 (reviewing)
  14. Stefan Bürk commented on patch set 3 11/19/26, 14:16

    Reply Unresolved

    IMO should we crerate the backports first and ensure to execute nightly on the backports too after the change in the other comment.

    DriverResultTest.php:38

    I'd say we should use a static value here and istead really use php serialization here. Special because if the backports. PHP serialization/deserialization changed between php minor versions, not hitting main but backports. Let's make that safe.
  15. Sebastian Mendel commented on patch set 3 11/19/26, 17:07

    DriverResultTest.php:38 Reply

    Not sure if I got you right, but: There is no serialization involved here: the test writes a static string literal and compares the bytes it reads back. The literal is what the core writes into `sys_registry.entry_value` for `Registry::set('…', '…', 'value')`, so the test mirrors a real row instead of an artificial value. The serialized form of a plain string has not changed across the PHP versions the backports support, so the backports are not affected either. I can switch to a neutral value if you prefer, but I'd rather keep the real-world one. Anyway, say the word, and I can replace it with something else.
  16. Benni Mack commented on patch set 3 11/19/26, 22:00

    DriverResultTest.php:38 Reply

    I don’t know what you mean with “say the word”? Which word? “Please”?
  17. Sebastian Mendel commented on patch set 3 11/19/26, 22:58

    DriverResultTest.php:38 Reply Unresolved

    "Please" is an option! ;-) , another option would yes or no, it doesn't matter, and I just only asked if the request still holds after explaining why it is written as it is written yet. To be absolutely clear: 'The idiom "say the word" means to give permission, a signal, or an instruction to act' But I still do not understand how this improves the patch. Will do.
  18. Sebastian Mendel uploaded patch set 4 CR +1 V +1 11/19/26, 23:00

  19. core-ci voted on patch set 4 V +1 11/19/26, 23:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/115037