@@ -193,9 +193,15 @@ private function getCurlCommand(array $trace): ?string
193
193
$ dataArg = [];
194
194
195
195
if ($ json = $ trace ['options ' ]['json ' ] ?? null ) {
196
- $ dataArg [] = '--data ' .escapeshellarg (self ::jsonEncode ($ json ));
196
+ if (!$ this ->argMaxLengthIsSafe ($ payload = self ::jsonEncode ($ json ))) {
197
+ return null ;
198
+ }
199
+ $ dataArg [] = '--data ' .escapeshellarg ($ payload );
197
200
} elseif ($ body = $ trace ['options ' ]['body ' ] ?? null ) {
198
201
if (\is_string ($ body )) {
202
+ if (!$ this ->argMaxLengthIsSafe ($ body )) {
203
+ return null ;
204
+ }
199
205
try {
200
206
$ dataArg [] = '--data ' .escapeshellarg ($ body );
201
207
} catch (\ValueError ) {
@@ -204,7 +210,10 @@ private function getCurlCommand(array $trace): ?string
204
210
} elseif (\is_array ($ body )) {
205
211
$ body = explode ('& ' , self ::normalizeBody ($ body ));
206
212
foreach ($ body as $ value ) {
207
- $ dataArg [] = '--data ' .escapeshellarg (urldecode ($ value ));
213
+ if (!$ this ->argMaxLengthIsSafe ($ payload = urldecode ($ value ))) {
214
+ return null ;
215
+ }
216
+ $ dataArg [] = '--data ' .escapeshellarg ($ payload );
208
217
}
209
218
} else {
210
219
return null ;
@@ -240,4 +249,14 @@ private function getCurlCommand(array $trace): ?string
240
249
241
250
return implode (" \\\n " , $ command );
242
251
}
252
+
253
+ /**
254
+ * Let's be defensive : we authorize only size of 8kio on Windows for escapeshellarg() argument to avoid a fatal error
255
+ *
256
+ * @see https://github.com/php/php-src/blob/9458f5f2c8a8e3d6c65cc181747a5a75654b7c6e/ext/standard/exec.c#L397
257
+ */
258
+ private function argMaxLengthIsSafe (string $ payload ): bool
259
+ {
260
+ return \strlen ($ payload ) < ('\\' === \DIRECTORY_SEPARATOR ? 8100 : 256000 );
261
+ }
243
262
}
0 commit comments