fix(response): avoid error if response is too long#246
Conversation
|
|
||
| $response = new Response(); | ||
| $response->loadXML($contents); | ||
| $loaded = @$response->loadXML($contents); |
There was a problem hiding this comment.
Makes sense. But I really do not like supression for functions. I think better try, catch or something like error handler. So see real message in line 53.
| { | ||
| $transactionKeyEncoded = $this->retrieveH00XTransactionKey($response); | ||
|
|
||
| if (null === $transactionKeyEncoded) { |
There was a problem hiding this comment.
Transaction key for some requests is not present, but for these requests extractInitializationSegment() should not be applied. This is more wrong usage exception here. I would say, that transactionKeyEncoded is required in this place and can be thrown appropriate exception if no transactionKeyEncoded.
| } | ||
|
|
||
| public function setTransactionKey(string $transactionKey): void | ||
| public function setTransactionKey(?string $transactionKey): void |
There was a problem hiding this comment.
I am not sure that it should be possible have not transactionKey for DownloadSegment.
| } | ||
|
|
||
| public function setTransactionKey(string $transactionKey): void | ||
| public function setTransactionKey(?string $transactionKey): void |
|
I've limited the maximum file size to 10MB because processing files of this size through AES, Base64, and Zip operations requires loading large amounts of data into memory, which can exceed PHP's memory limit. |
fix(response): avoid error if response is too long / truncated
Problem
When the EBICS server returns a very long (in my case Large response size: 1051214 bytes, in ebics 2.4 for Société générale bank) or truncated response, the XML body can become malformed. This currently leads to two cascading issues:
HttpClient::post()uses@$response->loadXML($contents), which suppresses the error and returnsfalse. The code continues with an empty/unloadedResponseobject, making debugging difficult.ResponseHandlerextracts the transaction key viaretrieveH00XTransactionKey(), which returnsnullwhen the expected node is missing. The code then immediately callsbase64Service->decode(null)on astring-typed parameter, causing aTypeErroror later null-pointer crashes insideSegment/DownloadSegmentwheretransactionKeyis declared as non-nullablestring.Solution
This PR adds defensive handling at every layer so that truncated responses fail early and explicitly instead of propagating cryptic type errors.
HttpClient.php)@suppression onloadXML. If parsing fails, throw a clearRuntimeException: "Failed to parse EBICS XML response. Response may be truncated or malformed."ResponseHandler.php)extractInitializationSegment(), check whetherTransactionKeyis present. If it isnull, throw immediately with: "EBICS initialization segment is missing TransactionKey. Response may be truncated."ResponseHandler.php)extractDownloadSegment(), allowtransactionKeyEncodedto benull. Passnullto the segment instead of crashing onbase64_decode(null).Segment.php,DownloadSegment.php)$transactionKeyfromstringto?string(and update getters/setters) so that a missing key is representable without violating type safety.