Skip to content

Commit ab6cef4

Browse files
Sanitize null bytes before quoteValue() on PHP 8.5+ in SQLite. (#20673)
1 parent 1fdceba commit ab6cef4

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

.github/workflows/ci-sqlite.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,27 @@ concurrency:
3939
group: ${{ github.workflow }}-${{ github.ref }}
4040
cancel-in-progress: true
4141

42+
env:
43+
PHP_EXTENSIONS: curl, intl, pdo, pdo_sqlite
44+
PHP_INI_VALUES: apc.enabled=1,apc.shm_size=32M,apc.enable_cli=1, date.timezone='UTC'
45+
PHPUNIT_GROUP: sqlite
46+
XDEBUG_MODE: coverage
47+
4248
jobs:
4349
tests:
4450
name: PHP ${{ matrix.php }}-sqlite
4551

4652
env:
47-
COVERAGE_DRIVER: ${{ matrix.php == 7.4 && 'xdebug' || 'none' }}
48-
PHP_EXTENSIONS: curl, intl, pdo, pdo_sqlite
49-
PHP_INI_VALUES: apc.enabled=1,apc.shm_size=32M,apc.enable_cli=1, date.timezone='UTC'
50-
PHPUNIT_GROUP: sqlite
51-
XDEBUG_MODE: coverage
53+
COVERAGE_DRIVER: xdebug
5254

5355
runs-on: ubuntu-latest
5456

5557
strategy:
5658
fail-fast: false
5759
matrix:
58-
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
60+
php: [7.4, 8.5]
5961

60-
steps:
62+
steps: &sqlite-steps
6163
- name: Monitor action permissions.
6264
if: runner.os != 'Windows'
6365
uses: GitHubSecurityLab/actions-permissions/monitor@v1
@@ -79,3 +81,18 @@ jobs:
7981
coverage-driver: ${{ env.COVERAGE_DRIVER }}
8082
coverage-token: ${{ secrets.CODECOV_TOKEN }}
8183
group: ${{ env.PHPUNIT_GROUP }}
84+
85+
tests-dev:
86+
name: PHP ${{ matrix.php }}-sqlite
87+
88+
env:
89+
COVERAGE_DRIVER: none
90+
91+
runs-on: ubuntu-latest
92+
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
php: [8.0, 8.1, 8.2, 8.3, 8.4]
97+
98+
steps: *sqlite-steps

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Yii Framework 2 Change Log
8181
- Bug #20665: Fix PHP `8.5` `null` array offset deprecation warnings in `yii\build\controllers\ReleaseController` class (terabytesoftw)
8282
- Bug #20658: Add missing generics in `yii\console`, `yii\captcha`, `yii\caching` and `yii\behaviors` namespaces (mspirkov)
8383
- Bug #20666: Add missing generics in `yii\base`, `yii\console`, `yii\filters` and `yii\web` namespaces (mspirkov)
84+
- Bug #20673: Sanitize `null` bytes before `quoteValue()` on PHP 8.5+ in SQLite (terabytesoftw)
8485
- Bug #20671: Fix PHPDoc annotations in `yii\base`, `yii\console`, `yii\web` and `yii\widgets` namespaces (mspirkov)
8586

8687

framework/db/sqlite/Schema.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,24 @@ private function isSystemIdentifier($identifier)
491491
{
492492
return strncmp($identifier, 'sqlite_', 7) === 0;
493493
}
494+
495+
/**
496+
* @inheritdoc
497+
*
498+
* Since PHP 8.5, `PDO::quote()` throws a ValueError when the string contains null bytes ("\0").
499+
*
500+
* This method sanitizes such bytes before calling the parent implementation to avoid exceptions while maintaining
501+
* backward compatibility.
502+
*
503+
* @link https://github.com/php/php-src/commit/0a10f6db26875e0f1d0f867307cee591d29a43c7
504+
*/
505+
public function quoteValue($value)
506+
{
507+
if (PHP_VERSION_ID >= 80500 && is_string($value) && str_contains($value, "\0")) {
508+
// Sanitize null bytes to prevent PDO ValueError on PHP 8.5+
509+
$value = str_replace("\0", '', $value);
510+
}
511+
512+
return parent::quoteValue($value);
513+
}
494514
}

0 commit comments

Comments
 (0)