Skip to content

Commit 9de7cbd

Browse files
committed
fix(corpus): initialize pooled _meta before exposing its view (Codex review)
The view-into-field fixture rented `_meta` but never wrote its valid bytes, so after.cs (the "clean fix" specificity half) still exposed 8 uninitialized pooled bytes via FlushMeta — a latent stale read in a file meant to be genuinely correct. Write `_meta[0.._metaLen)` (Fill) before caching the bounded view, mirroring the `_buf`/Fill path, in both before.cs and after.cs so the "valid payload + stale tail" story holds. No checker-behaviour change: before still raises OWN025 on both full-length field stores, after stays silent (verified via own-check.sh --format sarif). case.own is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cg6DVXahkyY68Ruu7f76rG
1 parent 2193d77 commit 9de7cbd

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎corpus/real-world/arraypool-view-into-field-overread/after.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public void Capture(int n)
2424
Fill(_buf, n);
2525
_view = _buf.AsMemory(0, _n); // FIX: bounded to the logical length
2626
_metaLen = 8;
27-
_metaView = _meta.AsMemory(0, _metaLen); // FIX: bounded
27+
Fill(_meta, _metaLen); // write the valid metadata bytes first...
28+
_metaView = _meta.AsMemory(0, _metaLen); // ...then expose only those (bounded — no stale tail)
2829
}
2930

3031
public byte[] Flush() => _view.ToArray();

‎corpus/real-world/arraypool-view-into-field-overread/before.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ sealed class FieldViewFramer : IDisposable
2828
// is cached into a ReadOnlyMemory field below.
2929
private readonly byte[] _meta = ArrayPool<byte>.Shared.Rent(64); // Length >= 64
3030
private ReadOnlyMemory<byte> _metaView;
31+
private int _metaLen;
3132

3233
public void Capture(int n)
3334
{
3435
_n = n;
3536
_buf = ArrayPool<byte>.Shared.Rent(n); // pooled buffer stored in a FIELD (Length >= n)
3637
Fill(_buf, n); // valid payload is _buf[0..n]
38+
_metaLen = 8;
39+
Fill(_meta, _metaLen); // valid payload is _meta[0.._metaLen)
3740
_view = _buf.AsMemory(); // <-- BUG: full-length view cached into a field
38-
_metaView = _meta.AsMemory(); // <-- BUG: full-length view into a ReadOnlyMemory field
41+
_metaView = _meta.AsMemory(); // <-- BUG: full view (past _metaLen) into a ReadOnlyMemory field
3942
}
4043

4144
public byte[] Flush() => _view.ToArray(); // reads the cached full view: n bytes + stale [n, Length) tail

0 commit comments

Comments
 (0)