Fix confusion between buffer size and variable field size#702
Merged
Enet4 merged 1 commit intoEnet4:masterfrom Oct 11, 2025
Merged
Fix confusion between buffer size and variable field size#702Enet4 merged 1 commit intoEnet4:masterfrom
Enet4 merged 1 commit intoEnet4:masterfrom
Conversation
According to the standard PS3.8 Annex D tables D.1-1 and D.1-2 <https://dicom.nema.org/medical/dicom/2025c/output/chtml/part08/chapter_D.html>, the maximum PDU length that the peers communicate to each other during association establishment, applies to "the variable field of the P-DATA-TF PDUs". The "variable field" refers to the bytes starting on the 7th, according to PS3.8 section 9.3.5 <https://dicom.nema.org/medical/dicom/2025c/output/chtml/part08/sect_9.3.5.html>, and thus does not include the header. The code was interpreting it as a mix of the correct length (especially in reader.rs and writer.rs), the length including the PDU header (especially in server.rs and client.rs) and the length including the PDU and the PDV header (especially in pdata.rs). This attempts to sort out the mess and uniformly use the same interpretation as the one the standard uses. A lot of it has to do with buffer size allocation: the buffers need room for maximum PDU size + the header.
Enet4
approved these changes
Oct 11, 2025
Owner
Enet4
left a comment
There was a problem hiding this comment.
Sounds great! Thank you again for tracking down these issues with dicom_ul!
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.
The code is using max_pdu_size as both a limit for the variable field of the PDU (i.e. excluding the PDU header) and as a limit for the PDU as a whole (i.e. including the PDU header). The latter is wrong and affects send() and receive() in both server and client (see the commit message for full citations). As a consequence:
In the belief that the std library might allocate more than necessary when crossing a size that is a power of 2, I've reduced the constants
DEFAULT_MAX_PDU,MINIMUM_PDU_SIZEandLARGE_PDU_SIZEby 6 (the size of the PDU header) so that the full PDU fits within a buffer with a length that is a power of two.