PDO inserts NULL byte at position 254 on SQL Server ntext column
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
try {
$pdo = new PDO('odbc:DRIVER={SQL Server};SERVER=SHS\HS2017,49011;DATABASE=OIDDB', '', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = 'SELECT name, description, protected, visible, value FROM oidplus_config';
$stmt = $pdo->query($query);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $row) {
if (($p = strpos($row['value'],"\0")) !== false) echo "PROBLEM: NULL BYTE FOUND AT ".$row['name']." AT POSITION $p\n";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
Resulted in this output:
PROBLEM: NULL BYTE FOUND AT oidplus_private_key AT POSITION 254
PROBLEM: NULL BYTE FOUND AT oidplus_public_key AT POSITION 254
But I expected this output instead:
(Nothing)
I have verified that in the database the NULL byte is not there. In the database, the field has the correct length, in PHP strlen() is 1 byte too much, because of the inserted NULL byte
This seems to be very similar to the bug described at https://bugs.php.net/bug.php?id=74021
The SQL table is created as follows:
USE [OIDDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[oidplus_config](
[name] [nvarchar](50) NOT NULL,
[value] [ntext] NOT NULL,
[description] [nvarchar](255) NULL,
[protected] [bit] NOT NULL,
[visible] [bit] NOT NULL,
CONSTRAINT [PK_oidplus_config] PRIMARY KEY CLUSTERED
(
[name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[oidplus_config] ADD DEFAULT ('0') FOR [protected]
GO
ALTER TABLE [dbo].[oidplus_config] ADD DEFAULT ('0') FOR [visible]
GO
PHP Version
8.4.1 (also tested with 8.3.6)
Operating System
Windows 10
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
Ejecuta el reproductor de PDO ODBC proporcionado contra la columna ntext de SQL Server e inspecciona el valor obtenido alrededor de la posición 254. No se especifica ningún archivo fuente ni ninguna prueba; se considera completado cuando PDO ya no devuelve un byte NULL insertado y la longitud de la cadena obtenida coincide con el valor de la base de datos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php, sql
- Área
- database
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100