PDO inserts NULL byte at position 254 on SQL Server ntext column
未关闭
还没有人认领这个 Issue。
Bug
Extension: pdo_odbc
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
针对 SQL Server 的 ntext 列运行提供的 PDO ODBC 复现程序,并检查位置 254 附近获取到的值。未指定源文件或测试;当 PDO 不再返回插入的 NULL 字节,且获取到的字符串长度与数据库值一致时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php, sql
- 领域
- database
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100