php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77273 array_walk_recursive corrupts value types leading to PDO failure
Submitted: 2018-12-09 16:29 UTC Modified: 2018-12-21 21:23 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: andreas at sassermann dot de Assigned:
Status: Closed Package: Arrays related
PHP Version: 7.2 OS: linux
Private report: No CVE-ID: None
 [2018-12-09 16:29 UTC] andreas at sassermann dot de
Description:
------------
After processing an array containing pdo options with array_walk_recursive, the PDO constructor fails with
exception:

PDO::__construct(): SQLSTATE[HY000]: General error: attribute value must be an integer

According to vardump, the option array is perfectly fine. The assumption, that some internal structure get corrupted is triggered by the fact that by doing an is_integer() on the array values, the array becomes usable again.

The problem has been reproduced using 
PHP 7.1.1 (cli) ( NTS )
PHP 7.2.12 (cli) (built: Nov  6 2018 15:07:37) ( NTS )

It does not occur with
PHP 7.0.30-0+deb9u1 (cli) (built: Jun 14 2018 13:50:25) ( NTS )

Test script:
---------------
Find testscript at github:

https://gist.github.com/a-sassermann/840bd057f579169dc44bc4eee85b158a

It contains 3 tests:

1. check using PDO with unmodified option array
2. do an array_walk_recursive on option array before using with PDO
3. after array_walk_recursive do an is_integer() on array values

Expected result:
----------------
All tests should succeed without error.

Actual result:
--------------
Test 2 fails with exception 
PDO::__construct(): SQLSTATE[HY000]: General error: attribute value must be an integer


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-21 19:54 UTC] andreas at sassermann dot de
-Summary: array_walk_recursive corrupts value types +Summary: array_walk_recursive corrupts value types leading to PDO failure -PHP Version: 7.1.25 +PHP Version: 7.3.0
 [2018-12-21 19:54 UTC] andreas at sassermann dot de
I could verify the bug with 7.3.0.
 [2018-12-21 21:23 UTC] cmb@php.net
-PHP Version: 7.3.0 +PHP Version: 7.2
 [2018-12-21 21:23 UTC] cmb@php.net
Thanks, Andreas!  Changing the affected version to 7.2, since this
is the oldest branch which would receive the bugfix.
 [2019-01-02 23:04 UTC] spotnyk at gmail dot com
I can confirm this issue. It's not just walk_recursive, but any use of referenced array content.

First experienced with: 7.1.8-2+ubuntu16.04.1+deb.sury.org+4

CANNOT reproduce with: 7.1.7-1+ubuntu16.04.1+deb.sury.org+1
 [2019-01-03 08:41 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=cb009b12a54c3dbb0e10b79c6ca77db8736d55b9
Log: Fixed bug #77273
 [2019-01-03 08:41 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC