Tcl Source Code

View Ticket
Login
Ticket UUID: 40ef293eed77dd168398cab4c98b20f553f2b7fc
Title: Path intrep invalidation triggered by [cd] too aggressive?
Type: Bug Created on: 2016-04-26 17:05:04
Submitter: dgp Assigned to: dgp
Subsystem: 37. File System Severity: Important
Priority: 5 Medium Last modified: 2016-06-23 17:26:42
Status: Open Closed by: nobody
Resolution: None Closed on:
Version:
Description:
Thanks to Brian Griffin for finding this:

% package require trofs
0.4.8
% file mkdir foo
% trofs::archive foo archive
% trofs::mount archive /mount
/mount
% cd /mount 
% glob *

Program received signal SIGSEGV, Segmentation fault.

It's a very difficult twisted problem to unravel.  Will
require much time and effort.  Until then, recording it
here, since it's far from clear whether more blame belongs
with trofs, or with the Tcl_Filesystem foundation.
User Comments:
dah added on 2016-06-17 04:33:51:
In trofs.c 
PathInFilesystem calls FetchDirFromCache -> FetchTrofsPath -> Tcl_FSGetInternalRep.

Tcl_FSGetInternalRep is doing a call back to PathInFileSystem because srcFsPathPtr->fsPtr is nil when first looking up /mount, srcFsPathPtr->fsPtr isn't set out until PathInFileSystem returns first, so it winds up in an infinite loop.

No idea how it is really supposed to go, just figured this might help someone that knows better :)

dgp added on 2016-06-23 17:20:45:
At its root, this is a shimmering problem that
trofs code didn't take enough care to handle.

Patch to trofs source code that appears to fix it:

diff -u -r1.27 trofs.c
--- generic/trofs.c     22 Jan 2015 17:07:00 -0000      1.27
+++ generic/trofs.c     23 Jun 2016 17:18:10 -0000
@@ -547,12 +547,22 @@
 
     Tcl_DictObjGet(NULL, dictPtr, pathPtr, &dirPathPtr);
     if (NULL != dirPathPtr) {
-       TrofsPath *tpPtr = FetchTrofsPath(dirPathPtr);
-       if (NULL == tpPtr) {
-           Tcl_DictObjRemove(NULL, dictPtr, pathPtr);
+       TrofsPath *tpPtr;
+
+       /* Remove item from cache to prevent endless loops */
+       Tcl_IncrRefCount(dirPathPtr);
+       Tcl_IncrRefCount(pathPtr);
+       Tcl_DictObjRemove(NULL, dictPtr, pathPtr);
+       tpPtr = FetchTrofsPath(dirPathPtr);
+       if (tpPtr) {
+           *tpPtrPtr = tpPtr;
+           Tcl_DictObjPut(NULL, dictPtr, pathPtr, dirPathPtr);
+       }
+       Tcl_DecrRefCount(pathPtr);
+       Tcl_DecrRefCount(dirPathPtr);
+       if (tpPtr == NULL) {
            return NULL;
        }
-       *tpPtrPtr = tpPtr;
     }
     return dirPathPtr;
 }

dgp added on 2016-06-23 17:25:50:
It's possible a case could be made that
core Tcl filesystem code is too aggressive
in invalidating absolute path internal reps
when the current working directory is changed.

The place to direct further examination
is in the epoch checking done in
Tcl_FSConvertToPathType().