Repository navigation
fix(serialization): deserialize empty multidimensional arrays - #11430
Conversation
There was a problem hiding this comment.
🟢 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.
Code coverage
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 |
…#11430) (cherry picked from commit 0e5deb7) Upstream-PR: dotnet#11430 Upstream-Commit: 0e5deb7
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
c7056b3ab620e5d3144ea72b12d572dc398c988dwith .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