Skip to content

[ul] Fix max PDU issues#733

Merged
Enet4 merged 4 commits intoEnet4:masterfrom
pgimeno4d:fix-max-pdu-reader-writer
Mar 4, 2026
Merged

[ul] Fix max PDU issues#733
Enet4 merged 4 commits intoEnet4:masterfrom
pgimeno4d:fix-max-pdu-reader-writer

Conversation

@pgimeno4d
Copy link
Copy Markdown
Contributor

@pgimeno4d pgimeno4d commented Feb 3, 2026

Rather than implementing (send/receive)_pdata in the generic traits (Sync/Async)Association, implement them in the specialization (Async?)(Client/Server)Association, which allows specifying which max PDU length to use, the requestor's or the acceptor's.

Fixes #712. Note there are no unit tests for send/ receive_pdata.

Rather than implementing (send/receive)_pdata in the generic traits (Sync/Async)Association, implement them in the specialization (Async?)(Client/Server)Association, which allows specifying which max PDU length to use, the requestor's or the acceptor's.
The AsyncPDataWriter type should be conditioned to feature `async`.
@pgimeno4d
Copy link
Copy Markdown
Contributor Author

I guess this change could do with unit tests that demonstrate the problem and how the patch fixes it, especially since #712 can no longer be reproduced by that issue's OP. Will work on it, although I haven't ever used send/receive_pdata.

@Enet4
Copy link
Copy Markdown
Owner

Enet4 commented Feb 11, 2026

I guess this change could do with unit tests that demonstrate the problem and how the patch fixes it, especially since #712 can no longer be reproduced by that issue's OP. Will work on it, although I haven't ever used send/receive_pdata.

Would it help if I pushed a branch with a baseline test which covers send_pdata and receive_pdata? I can probably make it available within the next few hours.

For what it's worth, there are tests for the underlying PDataWriter and PDataReader implementations, so this may be a case of passing the wrong PDU size limits to them.


Update: see master...chore/test-association_store_pdata

@pgimeno4d
Copy link
Copy Markdown
Contributor Author

Would it help if I pushed a branch with a baseline test which covers send_pdata and receive_pdata? I can probably make it available within the next few hours.

I guess it could help me see how to use them and see them integrated in a test. If not, I already have the findscu (for receive_pdata) and storescu (for send_pdata) examples. My plan is to stress the maximum PDUs in a manner similar to what #685 did: choose different maximums for the server and the client, and check that it can send and receive exactly that and not one more byte, and then switch sides, to guarantee that no combination is missed.

For what it's worth, there are tests for the underlying PDataWriter and PDataReader implementations, so this may be a case of passing the wrong PDU size limits to them.

Yeah, the problem affects send_pdata and receive_pdata only, as the implementations of these are passing values of max PDU to the PDataReader/Writer which are adequate from a client's standpoint only, even when called from a ServerAssociation, as the trait is common to both server and client and they use the default implementation from mod.rs instead of a specialized implementation for each.

In fact this patch just removes the default implementation and creates specializations with the correct values (mostly a copy/paste but carefully reviewed case by case because these are very error-prone).

@pgimeno4d
Copy link
Copy Markdown
Contributor Author

After examining the code, I think I can test send_pdata from the receiver's side, but I don't see how to test receive_pdata, since it calls read_pdu with strict set to false:

match read_pdu(&mut buf, self.max_data_length, false)

Therefore no error is ever produced, and the only consequence is that internal buffers may need reallocation due to short initial capacity, which is not something visible from the outside.

So, working on a patch that tests just send_pdata.

@pgimeno4d
Copy link
Copy Markdown
Contributor Author

Update: see master...chore/test-association_store_pdata

I've just noticed your update; unfortunately edits don't send notifications so I missed it earlier, sorry.

It's good for a full protocol test. For testing specific parts, like the exact size of the PDU, I'd rather abuse association_echo.rs, though, which already has the connection establishment infrastructure and is designed to deal with packets of arbitrary lengths, even if the packet contents are not standard. I've based my test on it.

Your test would be a nice addition as an "overall high-level test".

This test fails unless the correct maximum is used for sending.
@pgimeno4d
Copy link
Copy Markdown
Contributor Author

Added the test that demonstrates the problem in current master. If the patch is not applied, the test fails.

@pgimeno4d
Copy link
Copy Markdown
Contributor Author

Pushed the change of strategy. Now the send_pdata and receive_pdata methods are the default ones again. I've given up on trying to mix the Sync and Async versions into one.

@Enet4 Enet4 added this to the DICOM-rs 0.9.1 milestone Mar 3, 2026
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.

All good now! Thank you!

@Enet4 Enet4 merged commit f93c225 into Enet4:master Mar 4, 2026
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.

Potential PDU length negotiation issue: SCU sends larger PDUs than its declared maximum

2 participants