php / php/php-src

Mysql PDO heap corruption on Win10 x64 1909 (PHP x86 NTS)

Open
#9,143 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: pdo_mysql Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
define('DB_DRIVER', 'mysql');
define('DB_HOST', 'localhost');
define('DB_PORT', 3306);
define('DB_USER', '[removed]');
define('DB_PASS', '[removed]');
define('DB_NAME', '[removed]');
define('DB_DSN' , DB_DRIVER.':dbname='.DB_NAME.';host='.DB_HOST.';port='.DB_PORT);
$params = array(
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_PERSISTENT => true,
  PDO::ATTR_EMULATE_PREPARES => false,
  PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION sql_mode='', group_concat_max_len=32000, time_zone='+00:00'"
);
$params[PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_OBJ;
$handle = new PDO(DB_DSN, DB_USER, DB_PASS, $params);

Resulted in this output:
Random crashes with the following in Event Viewer:

Faulting application name: php-cgi.exe, version: 8.1.8.0, time stamp: 0x62c4c3bb
Faulting module name: ntdll.dll, version: 10.0.18362.719, time stamp: 0x832e7bce
Exception code: 0xc0000374
Fault offset: 0x000df95d
Faulting process id: 0x5458
Faulting application start time: 0x01d8a070256f66a2
Faulting application path: C:\Program Files (x86)\php81\php-cgi.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: a41ae7dc-55de-4152-b401-9553e23d1b5d
Faulting package full name: 
Faulting package-relative application ID: 

But I expected this output instead:

Successful database connection and no crashing.

Other notes:
This issue seems to be somewhat random, but I was able to get it to consistently crash if I kill the idle db connection via the sql command kill <id>;, then refresh the page. Using IIS 10 configured to hand-off the request to php via fastcgi. Database server attempting to connect to is on the same machine - Version: 10.4.12-MariaDB-log - Win10 x64. DebugDiag log attached (zipped due to file ext limitation on github).

php-cgi.exe_220725_131714_CrashHangAnalysis.zip

PHP Version

PHP 8.1.8 x86 NTS

Operating System

Windows 10 x64 1909

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PDO connection shown in the issue with persistent connections, then kill the idle MariaDB connection and refresh through IIS FastCGI. Inspect the attached DebugDiag log and the PDO MySQL connection and reconnect paths; done means the same sequence no longer causes a heap-corruption crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
mariadb, mysql, php
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.