DiskUtils.TryGetReparseDataBuffer reads a struct from unzeroed pooled memory and ignores the number of bytes returned
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 57/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C#
- Stars
- 109
- Forks
- 26
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ForNeVeR/TruePath
-
Wrong values of Kernel32.FileShare.Delete and Kernel32.FileAttributes.PosixSemanticsPossibly taken @ElectLive claimed this 2 days ago. Openbug good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 83/100
ForNeVeR/TruePath#241 · 1 comment ·
Maintainers usually reply within 1 day
-
AbsolutePath.ReadKind allocates a new 16 KiB buffer per directory on Windows: the pooled buffer is not returned on failurePossibly taken @FalconTechDev claimed this 2 days ago. Openenhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ForNeVeR/TruePath#240 · 1 reaction ·
Maintainers usually reply within 1 day
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ForNeVeR/TruePath#165 · 2 comments ·
Maintainers usually reply within 1 day
-
Windows tests: symlink access requires dev mode or elevated accessPossibly taken @hamdiakin claimed this 1 day ago. Opendocumentation help wanted
Difficulty 3/5 1-2 days Newbie friendliness 57/100
ForNeVeR/TruePath#245 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement help wanted
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
All issues in ForNeVeR/TruePath
Similar issues
-
[BUG]: Position intent set on a simple order is dropped when it becomes a bracket, OCO or OTO orderPossibly taken @RaphaelFakhri claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
alpacahq/alpaca-trade-api-csharp#903 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
joinrpg/joinrpg-net#5752 ·
Maintainers usually reply within 1 day
-
bug ux
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CodeForFire/lagebuch#714 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dimitar-radenkov/Pointframe#294 ·
Maintainers usually reply within 1 day
-
kind/feature-request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Altinn/altinn-correspondence#2154 ·
Maintainers usually reply within 1 day