Incorrect base64 encoding in PHP-FPM with opcache.file_cache_only=1 and sodium
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.1k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
The following code:
<?php
final class SodiumBase64Polyfill
{
public const SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING = 3;
public const SODIUM_BASE64_VARIANT_URLSAFE = 5;
public const SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING = 7;
public static function bin2base64(string $decoded, int $variant): string
{
if (! function_exists('sodium_bin2base64')) {
return self::bin2base64Fallback($decoded, $variant);
}
return sodium_bin2base64($decoded, $variant);
}
public static function bin2base64Fallback(string $decoded, int $variant): string
{
$encoded = base64_encode($decoded);
if (
$variant === self::SODIUM_BASE64_VARIANT_URLSAFE
|| $variant === self::SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING
) {
$encoded = strtr($encoded, '+/', '-_');
}
if (
$variant === self::SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING
|| $variant === self::SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING
) {
$encoded = rtrim($encoded, '=');
}
return $encoded;
}
}
var_dump(SodiumBase64Polyfill::bin2base64("Hello world!", SodiumBase64Polyfill::SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING));
Resulted in this output:
"Hello world!�"
But I expected this output instead:
"SGVsbG8gd29ybGQh"
Steps to reproduce
- Run PHP-FPM with the following php.ini settings:
zend_extension=opcache.so
extension=sodium.so
opcache.enable = 1
opcache.enable_cli = 1
; Tune opcache for read-only application files
opcache.revalidate_freq=0
opcache.validate_timestamps=false
opcache.enable_file_override=1
; Enable pre-warmed opcache
opcache.file_cache = "/var/cache/opcache"
opcache.file_cache_read_only=1
opcache.file_cache_consistency_checks=0
; Enable log
opcache.error_log=/dev/stderr
opcache.log_verbosity_level = 4
- Compile and run the script using:
php -d zend_extension=opcache.so \
-d extension=sodium.so \
-d opcache.enable=1 \
-d opcache.enable_cli=1 \
-d opcache.jit=disable \
-d opcache.file_cache=/var/cache/opcache \
-d opcache.file_cache_only=1 \
-d opcache.file_cache_read_only=0 ./public/index.php
- Send request php-fpm
Additional information
- The issue disappears when opcache.optimization_level=0 is set.
- The bug is tested with the file_cache_only feature introduced in PR #16551, but the issue also reproduces in PHP 8.4.
PHP Version
master, 8.4
Operating System
linux x86 or aarch64
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el fallo utilizando los comandos PHP-FPM y CLI proporcionados contra public/index.php, con y sin opcache.file_cache_only=1 y optimization_level=0. Lee el comportamiento de file_cache_only introducido por PR #16551 y sigue la interacción con sodium durante la compilación. El trabajo estará terminado cuando el script devuelva de forma consistente "SGVsbG8gd29ybGQh" con las configuraciones indicadas, sin regresiones en el comportamiento normal de opcache.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- linux, php
- Área
- backend, performance
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 32/100