Skip to content

Improve validation for data fragments for PSRP frame headers - #27871

Merged
Travis Plunk (TravisEz13) merged 1 commit into
PowerShell:masterfrom
anamnavi:remoting-fragment
Aug 20, 2026
Merged

Improve validation for data fragments for PSRP frame headers#27871
Travis Plunk (TravisEz13) merged 1 commit into
PowerShell:masterfrom
anamnavi:remoting-fragment

Conversation

@anamnavi

@anamnavi Anam Navied (anamnavi) commented Aug 20, 2026

Copy link
Copy Markdown
Member

This pull request refines the logic for handling received data fragments in the ProcessRawData method of PriorityCollection.cs. The main improvements are to the enforcement of the maximum object size limit and the order of checks, ensuring more accurate and robust processing of incoming data. These changes make the data processing logic more robust, especially in scenarios where large or incomplete data fragments are received.

Key changes to object size limit enforcement and data processing:

  • The check for exceeding the maximum allowed object size (_maxReceivedObjectSize) is now performed before confirming that the complete data fragment has been received, using a new temporary variable (totalSizeToBeReceived) to avoid prematurely updating the running total. The running total (_totalReceivedObjectSizeSoFar) is only updated after the entire fragment has been received.
  • The check for whether enough data has been received to process the packet (_pendingDataStream.Length < totalLengthOfFragment) has been moved after the object size limit check, ensuring that size limits are enforced even if the fragment is incomplete.
  • Exception handling has been slightly improved by catching OverflowException directly (instead of System.OverflowException).

PR Summary

PR Context

PR Checklist

Copilot AI lite review requested due to automatic review settings August 20, 2026 17:35
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@anamnavi Anam Navied (anamnavi) changed the title Improve validation for data fragments once a frame header is available Improve validation for data fragments for PSRP frame headers Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens fragment receive/defragment logic in ReceiveDataCollection.ProcessRawData by enforcing the configured maximum received object size based on the fragment header as soon as it’s available (even when the fragment payload has not fully arrived yet), while avoiding prematurely mutating the running size total.

Changes:

  • Computes a temporary totalSizeToBeReceived and validates it against _maxReceivedObjectSize before the “enough bytes received” check, so oversize frames are rejected early.
  • Updates _totalReceivedObjectSizeSoFar only after the complete fragment is present, preventing partial fragments from inflating the running total.
  • Simplifies the overflow catch to OverflowException while retaining the same behavior on arithmetic overflow.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Aug 20, 2026
@TravisEz13
Travis Plunk (TravisEz13) merged commit 68437b2 into PowerShell:master Aug 20, 2026
44 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants