DiskUtils.TryGetReparseDataBuffer reads a struct from unzeroed pooled memory and ignores the number of bytes returned
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
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
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:
- Pooled arrays are not zeroed, and the number of bytes written by
DeviceIoControlis ignored. The span covers the whole (larger-than-needed) array, soTryReadalways succeeds, even when the driver returned fewer bytes thansizeof(SymbolicLinkReparseBuffer)(20 bytes). Reparse points with little or no payload leave the remaining fields filled with leftovers of whatever previously used the pooled array. SymbolicLinkReparseBufferis a symlink-specific layout. ItsFlagsfield only exists for symlinks. For junctions (mount points), and for other tags, the same four bytes arePathBuffercontents 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
lpBytesReturnedand usenew Span<byte>(buffer, 0, (int)bytesReturned), so thatTryReadfails 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 allIsJunctionneeds), 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
Flagsis valid only forIO_REPARSE_TAG_SYMLINK.
- Lingua principale
- C#
- Stelle
- 107
- Fork
- 22
- Merge medio
- 3g 2h
- PR unite (30g)
- 13
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ForNeVeR/TruePath
-
Wrong values of Kernel32.FileShare.Delete and Kernel32.FileAttributes.PosixSemanticsForse già presa @ElectLive l’ha presa 2 giorni fa. Apertabug good first issue help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 83/100
ForNeVeR/TruePath#241 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
AbsolutePath.ReadKind allocates a new 16 KiB buffer per directory on Windows: the pooled buffer is not returned on failureForse già presa @FalconTechDev l’ha presa 1 giorno fa. Apertaenhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ForNeVeR/TruePath#240 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ForNeVeR/TruePath#165 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Windows tests: symlink access requires dev mode or elevated accessForse già presa @hamdiakin l’ha presa 1 giorno fa. Apertadocumentation help wanted
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
ForNeVeR/TruePath#245 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement help wanted
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ForNeVeR/TruePath
Issue simili
-
area-TableView bug needs-triage team-Controls
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
microsoft/microsoft-ui-xaml#12351 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
AudioClient and ImageClient file path overloads send the full local path as the multipart file nameForse già presa @sebxt l’ha presa oggi. Apertaarea: audio area: images feature-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
openai/openai-dotnet#1453 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
elsa-workflows/elsa-foundation#3130 ·
I maintainer di solito rispondono entro 1 giorno
-
遥测历史查询始终返回 HTTP 400,页面静默无结果Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100