Fix inbound command payload truncation at 1000 wide chars in connector DLLs#308
Open
biohazardxxx wants to merge 4 commits into
Open
Fix inbound command payload truncation at 1000 wide chars in connector DLLs#308biohazardxxx wants to merge 4 commits into
biohazardxxx wants to merge 4 commits into
Conversation
convertSystemString copied at most 1000 wchars into the caller's MQL string buffer regardless of its actual capacity and never wrote a null terminator (stale content from a previous, longer error message could leak into reused buffers). Command payloads longer than 1000 characters arrived truncated in the EA and failed JSON parsing. - convertSystemString now takes the destination capacity, bounds the copy and always null-terminates. - getPayload keeps its signature but honors the EA's real 5000-wchar payload buffer (StringInit(payload, 5000, 0)) instead of 1000. - New size-aware export getPayload2(handle, res, capacity, err) returns the full payload length (or -1 on error) and copies at most capacity-1 chars, so callers can re-allocate and fetch payloads of any size. Applies to both MT5Connector and MTConnector. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
GetJsonPayload now asks the connector for the payload with an explicit buffer capacity and re-allocates when the reported size exceeds the default 5000-character buffer, removing the previous hard cap on inbound command payloads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Same change as the MQL5 expert: GetJsonPayload re-allocates its buffer based on the size reported by getPayload2, removing the inbound payload cap. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inbound command payloads (client → EA) were silently truncated at 1000 wide characters by
convertSystemStringin both connector DLLs, even though the experts allocate a 5000-character payload buffer (StringInit(payload, 5000, 0)). Any command whose JSON payload exceeded 1000 characters arrived cut off mid-JSON, failed parsing in the EA and surfaced asFailed to get payload— an error that looks like a transport bug. The helper also never wrote a null terminator, so a shorter error message written into a reused_errorbuffer could leak the tail of a previous, longer one.This PR removes the cap entirely:
convertSystemString(dest, src, capacity)now receives the destination capacity, bounds the copy and always null-terminates.getPayloadkeeps its signature (old EAs keep working) but honors the expert's real 5000-character buffer instead of 1000.GetJsonPayloadin both experts (MQL4 + MQL5) fetches viagetPayload2with the default 5000-character buffer and, when the reported size is larger, re-allocates to the exact size and fetches again — one connector round-trip in the common case, two for oversized payloads.Implementation notes
MtExpert::GetCommandPayload()readscurrent_task_non-destructively; the task is only consumed onSendResponse.MtCommand/WebSocket transport already handle arbitrary payload sizes — the cap was exclusively in this one copy helper.MT5ConnectorandMTConnector; recompiledMtApi5.ex5andMtApi.ex4are included.getPayloadpath, now capped at 4999 instead of 1000). New EA requires the new DLL (importsgetPayload2); DLL and expert ship together in the installer.Testing
MT5Connector(x64) andMTConnector(Win32) build clean in Release;MtApi5.mq5andMtApi.mq4compile withResult: 0 errors, 0 warnings.Printwith a 6015-character message (payload above even the 5000 default buffer, exercising the re-allocate path): returnstrue, EA parses and executes the command..ex5: the same 6015-character command fails withFailed to get payload— reproducing the original defect and confirming the fix is what makes the difference.Removes the payload-size caveat documented in #307 (struct-array commands no longer need client-side chunking once both land).
🤖 Generated with Claude Code