[go] io/fs: document that Sub does not check for existence

2 views
Skip to first unread message

Sean Liao (Gerrit)

unread,
Feb 6, 2026, 4:08:23 PM (11 hours ago) Feb 6
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao has uploaded the change for review

Commit message

io/fs: document that Sub does not check for existence

Also recommend os.Root for constraining access.

Fixes #77447
Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35

Change diff

diff --git a/src/io/fs/sub.go b/src/io/fs/sub.go
index 376d561..63c7a3c 100644
--- a/src/io/fs/sub.go
+++ b/src/io/fs/sub.go
@@ -24,7 +24,8 @@
// Otherwise, Sub returns a new [FS] implementation sub that,
// in effect, implements sub.Open(name) as fsys.Open(path.Join(dir, name)).
// The implementation also translates calls to ReadDir, ReadFile,
-// ReadLink, Lstat, and Glob appropriately.
+// ReadLink, Lstat, and Glob appropriately. Sub does not check if the
+// directory currently exists.
//
// Note that Sub(os.DirFS("/"), "prefix") is equivalent to os.DirFS("/prefix")
// and that neither of them guarantees to avoid operating system
@@ -32,6 +33,7 @@
// does not check for symbolic links inside "/prefix" that point to
// other directories. That is, [os.DirFS] is not a general substitute for a
// chroot-style security mechanism, and Sub does not change that fact.
+// Use [os.Root] to constrain access to particular directory trees.
func Sub(fsys FS, dir string) (FS, error) {
if !ValidPath(dir) {
return nil, &PathError{Op: "sub", Path: dir, Err: ErrInvalid}

Change information

Files:
  • M src/io/fs/sub.go
Change size: XS
Delta: 1 file changed, 3 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35
Gerrit-Change-Number: 742284
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Damien Neil (Gerrit)

unread,
Feb 6, 2026, 5:52:29 PM (10 hours ago) Feb 6
to goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Sean Liao

Damien Neil voted and added 1 comment

Votes added by Damien Neil

Code-Review+2

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Damien Neil . resolved

Thanks.

Open in Gerrit

Related details

Attention is currently required from:
  • Sean Liao
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35
Gerrit-Change-Number: 742284
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Attention: Sean Liao <se...@liao.dev>
Gerrit-Comment-Date: Fri, 06 Feb 2026 22:52:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Pratt (Gerrit)

unread,
Feb 6, 2026, 6:22:58 PM (9 hours ago) Feb 6
to goph...@pubsubhelper.golang.org, Michael Pratt, Damien Neil, Go LUCI, golang-co...@googlegroups.com
Attention needed from Sean Liao

Michael Pratt voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Sean Liao
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35
    Gerrit-Change-Number: 742284
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Comment-Date: Fri, 06 Feb 2026 23:22:54 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Sean Liao (Gerrit)

    unread,
    Feb 6, 2026, 7:01:57 PM (9 hours ago) Feb 6
    to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Michael Pratt, Damien Neil, Go LUCI, golang-co...@googlegroups.com

    Sean Liao submitted the change

    Change information

    Commit message:
    io/fs: document that Sub does not check for existence

    Also recommend os.Root for constraining access.

    Fixes #77447
    Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35
    Reviewed-by: Damien Neil <dn...@google.com>
    Reviewed-by: Michael Pratt <mpr...@google.com>
    Files:
    • M src/io/fs/sub.go
    Change size: XS
    Delta: 1 file changed, 3 insertions(+), 1 deletion(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +2 by Damien Neil, +1 by Michael Pratt
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id8d178163438e9264fe19ed37ba03e1ee5d0bd35
    Gerrit-Change-Number: 742284
    Gerrit-PatchSet: 2
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages