Skip to content

Fix confusion between buffer size and variable field size#702

Merged
Enet4 merged 1 commit intoEnet4:masterfrom
pgimeno4d:fix-max-pdu-interpretation
Oct 11, 2025
Merged

Fix confusion between buffer size and variable field size#702
Enet4 merged 1 commit intoEnet4:masterfrom
pgimeno4d:fix-max-pdu-interpretation

Conversation

@pgimeno4d
Copy link
Copy Markdown
Contributor

@pgimeno4d pgimeno4d commented Oct 6, 2025

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:

  • A compliant client or server that doesn't use this library could send a well-formed PDU that would be rejected by a peer that uses the library.
  • A compliant server or client that uses this library could attempt to send a perfectly valid PDU and be wrongfully stopped by the library.

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_SIZE and LARGE_PDU_SIZE by 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.

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 Enet4 added bug This is a bug A-lib Area: library C-ul Crate: dicom-ul labels Oct 9, 2025
@Enet4 Enet4 self-requested a review October 9, 2025 07:59
Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! Thank you again for tracking down these issues with dicom_ul!

@Enet4 Enet4 merged commit 2ec7842 into Enet4:master Oct 11, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lib Area: library bug This is a bug C-ul Crate: dicom-ul

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants