Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

DiskUtils.TryGetReparseDataBuffer reads a struct from unzeroed pooled memory and ignores the number of bytes returned

Aperta
#242 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Start with TruePath/DiskUtils.cs at TryGetReparseDataBuffer and inspect how DeviceIoControl reports the number of bytes returned. Check how IsJunction consumes the result and how SymbolicLinkReparseBuffer represents tag-specific fields. Done when short responses cannot produce a successful read of stale data and fields are interpreted according to the reparse tag.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug good first issue help wanted

DiskUtils.TryGetReparseDataBuffer reads a SymbolicLinkReparseBuffer out of a buffer rented from ArrayPool<byte>.Shared:

byte[] buffer = ArrayPool<byte>.Shared.Rent(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
// ... DeviceIoControl(..., out _, ...)   // bytes returned are discarded
Span<byte> bufferSpan = new(buffer);
success = MemoryMarshal.TryRead(bufferSpan, out SymbolicLinkReparseBuffer reparseDataBuffer);

Two things are wrong here:

  1. Pooled arrays are not zeroed, and the number of bytes written by DeviceIoControl is ignored. The span covers the whole (larger-than-needed) array, so TryRead always succeeds, even when the driver returned fewer bytes than sizeof(SymbolicLinkReparseBuffer) (20 bytes). Reparse points with little or no payload leave the remaining fields filled with leftovers of whatever previously used the pooled array.
  2. SymbolicLinkReparseBuffer is a symlink-specific layout. Its Flags field only exists for symlinks. For junctions (mount points), and for other tags, the same four bytes are PathBuffer contents or arbitrary data.

No wrong result is observable today, because the only consumer, DiskUtils.IsJunction, reads just ReparseTag, which is always in the first four bytes of a successful response. But the method is a trap for the next person who reads another field. It reads uninitialized (stale) data and returns a struct whose fields can be garbage while the method reports success.

Recommendations

  • Capture lpBytesReturned and use new Span<byte>(buffer, 0, (int)bytesReturned), so that TryRead fails for a response that's too short.
  • Better: make the method return only what it can actually vouch for. Either return just the ReparseTag (that's all IsJunction needs), or expose a header-only struct (ReparseTag, ReparseDataLength, Reserved) and parse the tag-specific part per tag.
  • Rename or document the struct accordingly, so it's clear that Flags is valid only for IO_REPARSE_TAG_SYMLINK.
Lingua principale
C#
Stelle
107
Fork
22
Merge medio
3g 2h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ForNeVeR/TruePath

Tutte le issue di ForNeVeR/TruePath

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.