Tcl Source Code

View Ticket
Login
2026-11-16
10:43 • Closed ticket [4d3f213029]: VFS support causes infinite recursion during 'fi... artifact: 14ce21c8af user: oehhar
10:41
[4d3f2130292dbfe3] infinite recursion during 'file exists' if working directory has been removed check-in: 57b7358a87 user: oehhar tags: core-8-6-branch
09:41
[4d3f2130292dbfe3] infinite recursion during 'file exists' if working directory has been removed check-in: 3dce174010 user: oehhar tags: core-9-0-branch
09:40
[4d3f2130292dbfe3] infinite recursion during 'file exists' if working directory has been removed check-in: ca784f17f6 user: oehhar tags: trunk, main
2026-11-15
17:01 • Ticket [4d3f213029] VFS support causes infinite recursion during 'file exist... artifact: 3f3b637d7f user: oehhar
2026-11-14
17:13 • Ticket [4d3f213029]: 4 changes artifact: 247d8450c9 user: oehhar
2026-11-12
08:50 • Ticket [4d3f213029]: 4 changes artifact: 10f979df60 user: oehhar
08:44
[4d3f213029] merge main closed check-in: 7cd59ab35f user: oehhar tags: eval-cwd-deleted
2026-10-22
20:31
Fix [4d3f213029] for the case where [pwd] already failed after the current directory was deleted: Tc... check-in: e2e5c2656c user: serhiy.storchaka tags: eval-cwd-deleted
2026-10-13
20:09 • Ticket [4d3f213029] VFS support causes infinite recursion during 'file exist... artifact: 104a0eeb21 user: serhiy.storchaka
20:08
Fix [4d3f213029]: evaluating a script sourced with a relative path after its current directory was d... check-in: 58b479ca8a user: serhiy.storchaka tags: eval-cwd-deleted
2023-04-25
15:21 • Ticket [4d3f213029] VFS support causes infinite recursion during 'file exist... artifact: c667ecbe65 user: jrioux
14:33 • Ticket [4d3f213029]: 4 changes artifact: 5d4ec96fe8 user: oehhar
14:17 • New ticket [4d3f213029]. artifact: 85e7c0bfd6 user: jrioux

Ticket UUID: 4d3f2130292dbfe33977659c2afe98c7bb86b668
Title: VFS support causes infinite recursion during 'file exists' if working directory has been removed
Type: Bug Created on: 2023-04-25 14:17:21
Submitter: jrioux Assigned to: nobody
Subsystem: 37. File System Severity: Important
Priority: 5 Medium Last modified: 2026-11-16 10:43:04
Status: Closed Closed by: oehhar
Resolution: Fixed Closed on: 2026-11-16 10:43:04
Version: 9.0.5, 9.1.0
Description:
Tested on Ubuntu 22.04 with Tcl 8.6.12 and VFS 1.4.2

The following minimal example causes tclsh to segfault (infinite recursion). Expected was that no segmentation fault occurs.

package require vfs
set testdir directory_for_testing_will_be_deleted
set testdir_abs [file join [pwd] $testdir]
file mkdir $testdir
cd $testdir
puts "Current working dir: [pwd]"
file delete $testdir_abs
puts "Current working dir: [pwd]"
puts "File exists: [file exists .]"
User Comments:
oehhar added on 2023-04-25 14:33:54:

Julien,

thanks for the bug report. Why is this related to vfs? The issue only happens with the package require vfs? But you only work on real files, do you?

On TCL8.6.13 32bit on Windows 10 64 bit, the example does not work, as one may not delete the working directory. By adding "-force" to delete, it works. But the pwd is adjusted, to point to a present folder.

Here is an interactive session:

% set testdir directory_for_testing_will_be_deleted
directory_for_testing_will_be_deleted
% set testdir_abs [file join [pwd] $testdir]
C:/myprograms/tcl8.6/bin/directory_for_testing_will_be_deleted
% file mkdir $testdir
% cd $testdir
% pwd
C:/myprograms/tcl8.6/bin/directory_for_testing_will_be_deleted
% file delete -force $testdir_abs
% pwd
C:/myprograms/tcl8.6/bin
% file exists .
1

Maybe, you also post the output of your program.

Take care, Harald


jrioux added on 2023-04-25 15:21:52:
Yes the bug is only reproducible with "package require vfs" and most likely only on linux.

Here the program output running in gdb:

(gdb) r
Starting program: /usr/bin/tclsh
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
% package require vfs
1.4.2
% set testdir directory_for_testing_will_be_deleted
directory_for_testing_will_be_deleted
% set testdir_abs [file join [pwd] $testdir]
/directory_for_testing_will_be_deleted
% file mkdir $testdir
% cd $testdir
% puts "Current working dir: [pwd]"
Current working dir: /directory_for_testing_will_be_deleted
% file delete $testdir_abs
% puts "Current working dir: [pwd]"
Current working dir:
% puts "File exists: [file exists .]"

Program received signal SIGSEGV, Segmentation fault.
0x00007fb74877effd in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
(gdb) bt
#0  0x00007fb74877effd in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#1  0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#2  0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#3  0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#4  0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#5  0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#6  0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#7  0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#8  0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#9  0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#10 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#11 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#12 0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#13 0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#14 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#15 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#16 0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#17 0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#18 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#19 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#20 0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#21 0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#22 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#23 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#24 0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#25 0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#26 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#27 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#28 0x00007fb74877f1c9 in Tcl_FSGetCwd () from /lib/x86_64-linux-gnu/libtcl8.6.so
#29 0x00007fb748796099 in Tcl_FSGetNormalizedPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
#30 0x00007fb748002c36 in ?? () from /usr/lib/tcltk/x86_64-linux-gnu/vfs1.4.2/libvfs1.4.2.so
#31 0x00007fb748780b9e in Tcl_FSGetFileSystemForPath () from /lib/x86_64-linux-gnu/libtcl8.6.so
--Type <RET> for more, q to quit, c to continue without paging--

The ?? in the stack trace should be VfsPathInFilesystem if I am not mistaken.

serhiy.storchaka added on 2026-10-13 20:09:22:

Not specific to VFS: in 9.0 and 9.1, where zipfs is always registered, the example crashes without any extension. When a script sourced with a relative path is evaluated after its current directory was deleted, its path cannot be normalized, and TclEvalEx() then jumped to its error handler before parsing a command, using uninitialized data and corrupting memory.

Proposed fix in branch eval-cwd-deleted: use the path as is, it is only used for location information. The script then gets the usual errors for pwd and glob. Test source-9.1.


oehhar added on 2026-11-12 08:50:53:

Fix effective on Windows. Will merge after CI due to "perhaps Linux only" given in the description.

Thanks for all, Harald


oehhar added on 2026-11-14 17:13:27:

Jan, you have removed the "core-eval-cwd-deleted". I did not find the CI run. Is it me? I have reset this tag.

Sorry, Harald


oehhar added on 2026-11-15 17:01:42:

CI fully clean. Will merge tomorrow.

Thanks for all, Harald


oehhar added on 2026-11-16 10:43:04:

Merged to:

  • main [ca784f17]
  • core-9-0-branch [3dce1740]
  • core-8-6-branch [57b7358a]

Bug closed.

Thanks for all, Harald