Skip to content

Pad array writes to the correct number of entries#166

Merged
Schamper merged 1 commit into
mainfrom
fix-array-write
Jul 20, 2026
Merged

Pad array writes to the correct number of entries#166
Schamper merged 1 commit into
mainfrom
fix-array-write

Conversation

@Schamper

Copy link
Copy Markdown
Member

Fixes #154

@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 11.64%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 12 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_benchmark_getattr_types 12.1 µs 10.8 µs +12.49%
test_benchmark_getattr_constants 11.9 µs 10.8 µs +10.79%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix-array-write (29ceaaa) with main (8fd1506)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

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 addresses issue #154 by ensuring fixed-size array fields (especially trailing arrays in structs) serialize to the full declared size by padding missing entries, and by erroring when writes exceed the declared static size.

Changes:

  • Pad static arrays on write when fewer than num_entries elements/characters are provided (base arrays, char[], wchar[]), while raising ArraySizeError on overflow.
  • Add/extend tests to validate correct padding behavior and overflow errors for uint8[], char[], and wchar[].
  • Fix a spelling typo in structure field-offset comments (“alligned” → “aligned”).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_types_wchar.py Adds regression tests for wchar[] padding and overflow behavior, including struct end-of-struct array cases.
tests/test_types_char.py Adds regression tests for char[] padding and overflow behavior, including struct end-of-struct array cases.
tests/test_types_base.py Adds regression tests for generic array padding on write (primitive and struct element arrays).
dissect/cstruct/types/wchar.py Pads static wchar[] writes to num_entries, raising ArraySizeError on overflow.
dissect/cstruct/types/char.py Pads static char[] writes to num_entries, raising ArraySizeError on overflow; broadens _write input types.
dissect/cstruct/types/base.py Pads static generic arrays to num_entries using element defaults, raising ArraySizeError on overflow.
dissect/cstruct/types/structure.py Comment spelling correction only.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dissect/cstruct/types/base.py Outdated
Comment thread dissect/cstruct/types/char.py Outdated
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (8fd1506) to head (29ceaaa).

Files with missing lines Patch % Lines
dissect/cstruct/types/char.py 0.00% 8 Missing ⚠️
dissect/cstruct/types/wchar.py 0.00% 5 Missing ⚠️
dissect/cstruct/types/base.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #166   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         22      22           
  Lines       2773    2785   +12     
=====================================
- Misses      2773    2785   +12     
Flag Coverage Δ
unittests 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread dissect/cstruct/types/base.py Outdated
@Schamper
Schamper merged commit 32253fe into main Jul 20, 2026
24 checks passed
@Schamper
Schamper deleted the fix-array-write branch July 20, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dumped structure size different due to truncated array

3 participants