Skip to content

Commit 103b56e

Browse files
[release/8.0] Don't assume all S_IFREG files are seekable (#122188)
Backport of #120736 to release/8.0 /cc @rzikm ## Customer Impact None, the change is in Debug build only and doesn't affect shipped product. ## Regression No, test failures started after adding/updating AzureLinux3 OS in CI matrix. ## Testing CI passes. ## Risk Low, can be considered test-only change as the changes don't propagate to shipped product. --------- Co-authored-by: Radek Zikmund <r.zikmund.rz@gmail.com>
1 parent 34de5e1 commit 103b56e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ private bool Init(string path, FileMode mode, FileAccess access, FileShare share
344344
// and for regular files (most common case)
345345
// avoid one extra sys call for determining whether file can be seeked
346346
_canSeek = NullableBool.True;
347-
Debug.Assert(Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0);
347+
348+
// we exclude 0-length files from the assert because those may may be pseudofiles
349+
// (e.g. /proc/net/route) and these are not seekable on all systems
350+
Debug.Assert(status.Size == 0 || Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0);
348351
}
349352

350353
fileLength = status.Size;

0 commit comments

Comments
 (0)