Skip to content

CfdpManager: size File Data PDUs from an initialized PDU header - #6367

Open
lestarch-autobot wants to merge 2 commits into
nasa:develfrom
JPL-Devin:devin/fix-6128-cfdp-filedata-pdu-header-size
Open

lestarch-autobot wants to merge 2 commits into
nasa:develfrom
JPL-Devin:devin/fix-6128-cfdp-filedata-pdu-header-size

Conversation

@lestarch-autobot

Copy link
Copy Markdown
Collaborator
Related Issue(s) Fixes #6128
Has Unit Tests (y/n) y
Documentation Included (y/n) y
Generative AI was used in this contribution (y/n) AI

Change Description

Svc::Ccsds::Cfdp::Transaction::sSendFileData (Svc/Ccsds/CfdpManager/TransactionTx.cpp) called FileDataPdu::getMaxFileDataSize() on a freshly constructed FileDataPdu before initialize(). PduHeader has no constructor and FileDataPdu()/PduBase() do not set it, so the entity-ID / sequence-number encoded widths and the large-file flag used to size the File Data payload were read from an uninitialized stack header.

The fix initializes the PDU header with the transaction's real source entity ID (LocalEid), transaction sequence number, destination entity ID and file offset before computing the capacity, so getMaxFileDataSize() returns MaxPduSize - <actual header size> - 4. The final initialize() call before sendFd reuses the same cached values; no FPP, parameter, default or public API change.

Also:

  • Svc/Ccsds/CfdpManager/docs/sdd.md: the OutgoingFileChunkSize row now states that every File Data PDU is additionally capped at MaxPduSize using the header size derived from the actual entity IDs / sequence number.
  • Unit tests: new Transaction.Class1TxWideEidFileDataPduSizing (two-byte LocalEid, OutgoingFileChunkSize = MaxPduSize, two File Data PDUs; asserts the first PDU exactly fills MaxPduSize and that every PDU, offset and payload is correct), and FileDataPduHelper.GetBufferSizeAndMaxSize now checks the exact getMaxFileDataSize() formula. The tester's PDU buffers / allocation bound were sized to MaxPduSize + PACKET_DESCRIPTOR_SIZE to match the buffer the engine actually requests (Engine::serializeAndSendPduOnChannel adds the packet descriptor); the previous < MaxPduSize bound could never admit a full-size PDU.

Rationale

Fixes #6128. With the default OutgoingFileChunkSize (981) the bug is masked because the chunk size binds first, but any deployment that raises the chunk size, or uses wider entity IDs / sequence numbers, could emit File Data PDUs larger than MaxPduSize (or undersized ones), depending on whatever happened to be on the stack. Sizing from the initialized header makes the payload capacity deterministic and always within MaxPduSize.

Testing/Review Recommendations

  • fprime-util generate --ut && fprime-util build --ut -j"$(nproc)" then ctest in build-fprime-automatic-native-ut: 134/135 unit test executables pass, including Svc_Ccsds_CfdpManager_ut_exe and Svc_Ccsds_CfdpManager_Types_ut_exe; the remaining one (Svc_WasmSequencer_ut_exe) could not be built in the sandbox for the same crates.io reason as below and is unrelated to this change.
  • The new Transaction.Class1TxWideEidFileDataPduSizing test was run against devel without the TransactionTx.cpp change and fails there (over-sized buffer request / only one PDU emitted), and passes with it.
  • TestDeploymentsProject/Ref: every target except the Svc/WasmSequencer Rust crate built (that cargo build needs crates.io, which the sandbox used here could not reach), so the Ref binary was not linked. No in-tree deployment instantiates CfdpManager (the FileHandlingCfdp subtopology is not used by Ref), so no GDS-level run was performed; the behavior is covered at the unit-test level.
  • Review focus: the two fdPdu.initialize(...) calls in sSendFileData must carry identical header fields (they do: same cached sourceEid/seqNum/destEid, same foffs), and the tester bound change in CfdpManagerTester.{hpp,cpp}.

Future Work

None.

Contributor Checklist

AI Usage (see policy)

This PR was authored by an AI agent (Devin): root-cause analysis of the issue, the TransactionTx.cpp fix, the unit-test additions, the SDD update, and this description were AI-generated, following the repository's fprime-maintenance, fprime-cpp-design and fprime-unit-testing skills, and validated by building and running the unit tests locally.

IAMAI

sSendFileData called FileDataPdu::getMaxFileDataSize() before
FileDataPdu::initialize(), so the File Data capacity was derived from
an uninitialized PduHeader (entity ID / sequence number widths and the
large-file flag). Initialize the header with the transaction's real
source EID, sequence number and destination EID before computing the
capacity so every File Data PDU stays within MaxPduSize.

Adds a regression test with a two-byte LocalEid and a non-binding
OutgoingFileChunkSize, and sizes the tester's PDU buffers to allow for
the packet descriptor prepended by the engine.

Fixes nasa#6128

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report — base devel

Overall (line): 85.94% → 85.91% (-0.03)
Regression threshold: 0.50% (line).

Regressions

(none over threshold)

Modules changed

Module Line Δ Function Δ Branch Δ
Fw/DataStructures 97.60 -0.27 96.95 +0.00 82.12 -0.36
Svc/Ccsds/CfdpManager 90.83 +0.03 96.89 +0.00 78.15 +0.05
Os/Generic/Types 92.50 +0.36 92.86 +0.00 74.77 +0.94

New modules

Module Line Function Branch
Fw/Prm 0.00 0.00 0.00

Modules without UTs

CFDP/Checksum/GTest, Drv/LinuxGpioDriver, Drv/LinuxI2cDriver, Drv/LinuxSpiDriver, Drv/Ports/DataTypes, Drv/PosixUartDriver, FppTestProject/FppTest/topology/async, FppTestProject/FppTest/topology/components/Comp, FppTestProject/FppTest/topology/components/Framework, FppTestProject/FppTest/topology/components/Receiver, FppTestProject/FppTest/topology/components/Sender, FppTestProject/FppTest/topology/guarded, FppTestProject/FppTest/topology/sync, FppTestProject/FppTest/topology/top_ports, FppTestProject/FppTest/topology/types, Fw/Com, Fw/Comp, Fw/FilePacket/GTest, Fw/Fpy, Fw/Obj, Fw/Port, Fw/Sm, Fw/Test, Fw/Types/GTest, Os/Models, Svc/Ccsds/Types, Svc/Ccsds/Utils, Svc/FatalHandler, Svc/Subtopologies/CdhCore, Svc/Subtopologies/ComCcsds, Svc/Subtopologies/ComCcsdsSdls, Svc/Subtopologies/ComFprime, Svc/Subtopologies/ComLoggerTee, Svc/Subtopologies/DataProducts, Svc/Subtopologies/DpCompression, Svc/Subtopologies/FileHandling, Svc/Subtopologies/FileHandlingCfdp, Svc/Subtopologies/FileHandlingCfdp/FileHandlingCfdpConfig, TestDeploymentsProject/Ref/DpDemo, TestDeploymentsProject/Ref/PingReceiver, TestDeploymentsProject/Ref/RecvBuffApp, TestDeploymentsProject/Ref/SendBuffApp, TestDeploymentsProject/Ref/Top, TestDeploymentsProject/Ref/TypeDemo, cmake/test/data/TestConfigDeployment, cmake/test/data/TestDeployment/TestBuildAutocoder, cmake/test/data/TestDeployment/TestDuplicateDirective, cmake/test/data/TestDeployment/TestHeaderAutocoder, cmake/test/data/TestDeployment/TestLinkDepends, cmake/test/data/TestDeployment/TestRelative, cmake/test/data/test-fprime-library/TestLibrary/TestComponent, cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CfdpManager: sSendFileData sizes file data from an uninitialised PduHeader

2 participants