Commit 382d2494805 for php

commit 382d24948058d1d586ea48c549a65eb41ac531c6
Author: Alexandre Daubois <alex.daubois@gmail.com>
Date:   Mon Sep 21 15:49:40 2026 +0200

    Fix GHSA-q23r-hr55-xmpg: out-of-bounds read on empty SOAP-ENC:arraySize

diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c
index 916d992f55d..32ba6c7524f 100644
--- a/ext/soap/php_encoding.c
+++ b/ext/soap/php_encoding.c
@@ -2021,7 +2021,7 @@ static int calc_dimension_12(const char* str)
 		}
 		str++;
 	}
-	return i;
+	return i != 0 ? i : 1;
 }

 static int* get_position_12(int dimension, const char* str)
diff --git a/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.phpt b/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.phpt
new file mode 100644
index 00000000000..1b39feeb1d0
--- /dev/null
+++ b/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.phpt
@@ -0,0 +1,80 @@
+--TEST--
+GHSA-q23r-hr55-xmpg: Unbounded array walk on empty wsdl:arraySize
+--EXTENSIONS--
+soap
+--INI--
+soap.wsdl_cache_enabled=0
+--FILE--
+<?php
+
+const WSDL = __DIR__ . '/GHSA-q23r-hr55-xmpg-wsdl.wsdl';
+
+function itemType() { return ['A', 'B', 'C']; }
+function sizeOnly() { return ['A', 'B', 'C']; }
+
+function request(string $operation): string {
+    return <<<XML
+        <?xml version="1.0"?>
+        <env:Envelope
+            xmlns:env="http://www.w3.org/2003/05/soap-envelope"
+            xmlns:m="urn:arraysize">
+
+            <env:Body>
+                <m:{$operation}/>
+            </env:Body>
+        </env:Envelope>
+        XML;
+}
+
+class ReplayClient extends SoapClient
+{
+    public function __construct(public string $arrayType) {
+        parent::__construct(WSDL);
+    }
+
+    public function __doRequest($request, $location, $action, $version, $oneWay = 0): ?string {
+        return <<<XML
+            <?xml version="1.0"?>
+            <env:Envelope
+                xmlns:env="http://www.w3.org/2003/05/soap-envelope"
+                xmlns:ns1="urn:arraysize"
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+                <env:Body>
+                    <ns1:{$this->arrayType}Response>
+                        <result xsi:type="ns1:{$this->arrayType}Array">
+                            <item xsi:type="xsd:string">A</item>
+                            <item xsi:type="xsd:string">B</item>
+                            <item xsi:type="xsd:string">C</item>
+                        </result>
+                    </ns1:{$this->arrayType}Response>
+                </env:Body>
+            </env:Envelope>
+            XML;
+    }
+}
+
+$server = new SoapServer(WSDL);
+$server->addFunction(['itemType', 'sizeOnly']);
+
+foreach (['itemType', 'sizeOnly'] as $operation) {
+    ob_start();
+    $server->handle(request($operation));
+    $response = ob_get_clean();
+
+    preg_match('/arraySize="[^"]*"/', $response, $matches);
+    echo 'encode ', $operation, ' => ', $matches[0] ?? 'none', "\n";
+}
+
+foreach (['ItemType', 'SizeOnly'] as $arrayType) {
+    $client = new ReplayClient($arrayType);
+    echo 'decode ', $arrayType, ' => ', json_encode($client->{lcfirst($arrayType)}()), "\n";
+}
+
+?>
+--EXPECT--
+encode itemType => arraySize="3"
+encode sizeOnly => arraySize="3"
+decode ItemType => ["A","B","C"]
+decode SizeOnly => ["A","B","C"]
diff --git a/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.wsdl b/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.wsdl
new file mode 100644
index 00000000000..55b5b9207f6
--- /dev/null
+++ b/ext/soap/tests/GHSA-q23r-hr55-xmpg-wsdl.wsdl
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
+             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+             xmlns:enc12="http://www.w3.org/2003/05/soap-encoding"
+             xmlns:tns="urn:arraysize"
+             targetNamespace="urn:arraysize">
+
+  <types>
+    <xsd:schema targetNamespace="urn:arraysize">
+      <xsd:import namespace="http://www.w3.org/2003/05/soap-encoding"/>
+
+      <xsd:complexType name="ItemTypeArray">
+        <xsd:complexContent>
+          <xsd:restriction base="enc12:Array">
+            <xsd:attribute ref="enc12:itemType" wsdl:itemType="xsd:string"/>
+            <xsd:attribute ref="enc12:arraySize" wsdl:arraySize=""/>
+          </xsd:restriction>
+        </xsd:complexContent>
+      </xsd:complexType>
+
+      <xsd:complexType name="SizeOnlyArray">
+        <xsd:complexContent>
+          <xsd:restriction base="enc12:Array">
+            <xsd:attribute ref="enc12:arraySize" wsdl:arraySize=""/>
+          </xsd:restriction>
+        </xsd:complexContent>
+      </xsd:complexType>
+    </xsd:schema>
+  </types>
+
+  <message name="emptyRequest"/>
+  <message name="itemTypeResponse"><part name="result" type="tns:ItemTypeArray"/></message>
+  <message name="sizeOnlyResponse"><part name="result" type="tns:SizeOnlyArray"/></message>
+
+  <portType name="ArrayPortType">
+    <operation name="itemType">
+      <input message="tns:emptyRequest"/>
+      <output message="tns:itemTypeResponse"/>
+    </operation>
+    <operation name="sizeOnly">
+      <input message="tns:emptyRequest"/>
+      <output message="tns:sizeOnlyResponse"/>
+    </operation>
+  </portType>
+
+  <binding name="ArrayBinding" type="tns:ArrayPortType">
+    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+    <operation name="itemType">
+      <soap:operation soapAction="itemType"/>
+      <input><soap:body use="encoded" namespace="urn:arraysize" encodingStyle="http://www.w3.org/2003/05/soap-encoding"/></input>
+      <output><soap:body use="encoded" namespace="urn:arraysize" encodingStyle="http://www.w3.org/2003/05/soap-encoding"/></output>
+    </operation>
+    <operation name="sizeOnly">
+      <soap:operation soapAction="sizeOnly"/>
+      <input><soap:body use="encoded" namespace="urn:arraysize" encodingStyle="http://www.w3.org/2003/05/soap-encoding"/></input>
+      <output><soap:body use="encoded" namespace="urn:arraysize" encodingStyle="http://www.w3.org/2003/05/soap-encoding"/></output>
+    </operation>
+  </binding>
+
+  <service name="ArrayService">
+    <port name="ArrayPort" binding="tns:ArrayBinding">
+      <soap:address location="test://"/>
+    </port>
+  </service>
+</definitions>
diff --git a/ext/soap/tests/GHSA-q23r-hr55-xmpg.phpt b/ext/soap/tests/GHSA-q23r-hr55-xmpg.phpt
new file mode 100644
index 00000000000..886b3ff9042
--- /dev/null
+++ b/ext/soap/tests/GHSA-q23r-hr55-xmpg.phpt
@@ -0,0 +1,65 @@
+--TEST--
+GHSA-q23r-hr55-xmpg: Out-of-bounds read on empty SOAP-ENC:arraySize
+--EXTENSIONS--
+soap
+--FILE--
+<?php
+
+function echo_back($data) { $GLOBALS['decoded'][] = $data; return null; }
+
+function request(string $arraySize, string $itemType = ''): string {
+    $itemTypeAttribute = $itemType === '' ? '' : "SOAP-ENC:itemType=\"{$itemType}\"";
+
+    return <<<XML
+        <?xml version="1.0"?>
+        <SOAP-ENV:Envelope
+            xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+            xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+            <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+                <echo_back>
+                    <data xsi:type="SOAP-ENC:Array" {$itemTypeAttribute} SOAP-ENC:arraySize="{$arraySize}">
+                        <item xsi:type="xsd:string">A</item>
+                        <item xsi:type="xsd:string">B</item>
+                        <item xsi:type="xsd:string">C</item>
+                    </data>
+                </echo_back>
+            </SOAP-ENV:Body>
+        </SOAP-ENV:Envelope>
+        XML;
+}
+
+function decode(SoapServer $server, string $request): string {
+    ob_start();
+    $server->handle($request);
+    $response = ob_get_clean();
+
+    if (str_contains($response, '<SOAP-ENV:Fault>')) {
+        return 'fault: ' . strip_tags($response);
+    }
+
+    return json_encode(array_pop($GLOBALS['decoded']));
+}
+
+$server = new SoapServer(null, ['uri' => 'http://test']);
+$server->addFunction('echo_back');
+
+$GLOBALS['decoded'] = [];
+
+foreach (['', ' ', 'abc', '*', '3', '2 2'] as $arraySize) {
+    echo var_export($arraySize, true), ' => ', decode($server, request($arraySize)), "\n";
+}
+
+echo "itemType => ", decode($server, request('', 'xsd:string')), "\n";
+
+?>
+--EXPECT--
+'' => ["A","B","C"]
+' ' => ["A","B","C"]
+'abc' => ["A","B","C"]
+'*' => ["A","B","C"]
+'3' => ["A","B","C"]
+'2 2' => [["A","B"],["C"]]
+itemType => ["A","B","C"]