Skip to content

fix(serialization): deserialize empty multidimensional arrays - #11430

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-fix-empty-multidimensional-arrays
Oct 8, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-fix-empty-multidimensional-arrays

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Problem

An empty multidimensional array has zero elements whenever any dimension is zero. The reader currently checks partial dimension products against the remaining payload before reaching a later zero, so a typed new int[2, 0] payload fails to deserialize.

Reproduced on upstream main c7056b3ab620e5d3144ea72b12d572dc398c988d with .NET 8.0.31 and .NET 10.0.12.

Solution

Recognize a zero dimension before applying element-count bounds checks. Nonempty arrays retain the division-before-multiplication guards which bound allocations and prevent product overflow. CLR array creation continues to validate dimension lengths, and element assignment continues to reject elements in empty arrays.

Compatibility and regression coverage

Frozen typed payloads captured from the unmodified main writer cover [2, 0], [0, 2], and a nonempty [1, 2] array. The fixed reader restores their dimensions and contents, and the current writer emits byte-for-byte identical payloads.

Focused coverage exercises every zero position in ranks two through four, multiple zero dimensions, a large partial product, shared empty-array references and following values, oversized nonempty dimensions, product overflow with a non-seekable reader, negative dimensions, and unexpected elements. The complete multidimensional-array test class passes all 43 cases on both .NET 8 and .NET 10.

Fixes #11391.

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 8, 2026 01:37

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.

🟢 Approval recommended

The focused fix preserves nonempty-array safeguards and is comprehensively covered by regression tests.

0 open findings

What changed in this PR

Fixes deserialization of multidimensional arrays containing zero-length dimensions while preserving existing allocation guards.

Changes:

  • Recognizes zero dimensions before element-count validation.
  • Adds regression, compatibility, malformed-payload, overflow, and aliasing coverage.
File Description
src/​Orleans.Serialization/​Codecs/​MultiDimensionalArrayCodec.cs Corrects validation for empty multidimensional arrays.
test/​Orleans.Serialization.UnitTests/​MultiDimensionalArrayTests.cs Adds comprehensive regression and edge-case tests.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 83.27% (117,902 / 141,589)
Branches 72.74% (34,936 / 48,026)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested c50ac22, not current main c7056b3.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

@ReubenBond
ReubenBond merged commit 0e5deb7 into dotnet:main Oct 8, 2026
92 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-empty-multidimensional-arrays branch October 8, 2026 03:34
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 22, 2026
ReubenBond added a commit that referenced this pull request Oct 23, 2026
(cherry picked from commit 0e5deb7)

Upstream-PR: #11430
Upstream-Commit: 0e5deb7
This was referenced Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty multidimensional arrays can fail deserialization when a later dimension is zero

2 participants