Use typed safe local file checks in SSD storage

ober

8460b02f01f2e31853b7162a16b8a4625c48ea51

diff --git a/.build.yml b/.build.yml
index dd5cffe..35ec0f9 100644
--- a/.build.yml
+++ b/.build.yml
@@ -5,7 +5,7 @@ packages:
   - make=4.4.1-r4
 sources:
   # Build dependency: full immutable commit, mirrored in dependencies.lock.json.
-  - "https://git.sr.ht/~lisp/jerboa#bb4035286612e288dd9851184464e6450e2dd32c"
+  - "https://git.sr.ht/~lisp/jerboa#b98aa23ec2a473d30bdd71e5c9681c9ec16318de"
   # The second source is the build subject selected by the SourceHut submitter.
   - https://git.sr.ht/~lisp/jerboa-android
 tasks:
@@ -14,6 +14,6 @@ tasks:
       test "$(apk info -v chez-scheme)" = chez-scheme-10.3.0-r2
       test "$(apk info -v git)" = git-2.54.0-r0
       test "$(apk info -v make)" = make-4.4.1-r4
-      test "$(git -C ../jerboa rev-parse HEAD)" = bb4035286612e288dd9851184464e6450e2dd32c
-      test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = 9e10bc1d5b2dbbdbd87aebccdc4a9bacde7a0238
+      test "$(git -C ../jerboa rev-parse HEAD)" = b98aa23ec2a473d30bdd71e5c9681c9ec16318de
+      test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = 18d86823fcb7a2aa532056bc51fa3df8dbebdc48
       JERBOA="chez --libdirs .:../jerboa/lib --script" make test
diff --git a/dependencies.lock.json b/dependencies.lock.json
index 06aa54f..116387d 100644
--- a/dependencies.lock.json
+++ b/dependencies.lock.json
@@ -11,8 +11,8 @@
   "generator_runtime": {
     "name": "jerboa",
     "repository": "https://git.sr.ht/~lisp/jerboa",
-    "commit": "bb4035286612e288dd9851184464e6450e2dd32c",
-    "tree": "9e10bc1d5b2dbbdbd87aebccdc4a9bacde7a0238"
+    "commit": "b98aa23ec2a473d30bdd71e5c9681c9ec16318de",
+    "tree": "18d86823fcb7a2aa532056bc51fa3df8dbebdc48"
   },
   "assurance_tools": {
     "osv_scanner": {
diff --git a/scripts/verify-supply-chain.sh b/scripts/verify-supply-chain.sh
index 036d783..ab32198 100755
--- a/scripts/verify-supply-chain.sh
+++ b/scripts/verify-supply-chain.sh
@@ -3,8 +3,8 @@ set -eu
 
 repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P)
 lock="$repo/dependencies.lock.json"
-jerboa_commit=bb4035286612e288dd9851184464e6450e2dd32c # gitsafe:ignore
-jerboa_tree=9e10bc1d5b2dbbdbd87aebccdc4a9bacde7a0238 # gitsafe:ignore
+jerboa_commit=b98aa23ec2a473d30bdd71e5c9681c9ec16318de # gitsafe:ignore
+jerboa_tree=18d86823fcb7a2aa532056bc51fa3df8dbebdc48 # gitsafe:ignore
 gradle_sha=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78
 jdk_macos_sha=8fa1eff40bb637a33613b2ccb8b12c70dc3661cc22cf8e784943715769a05336
 jdk_linux_sha=d8afc263758141a66e0e3aafc321e783f7016696f4eaea067d340a269037d331
diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 7729cfb..ef1ce46 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1558,7 +1558,10 @@
             limit))))
 
     (typed-kotlin-file "com/sfb/ssdreview/TruthStoreRecords.kt"
-      (kotlin-imports (java io File) (java net URL))
+      (kotlin-imports (java io File)
+                      (java net URL)
+                      (java nio file Files)
+                      (java nio file Path))
       (typed-library (com sfb ssdreview)
         (export make-RemoteConfig RemoteConfig?
                 RemoteConfig-apiUrl RemoteConfig-spkiSha256 RemoteConfig-bearerToken
@@ -1569,13 +1572,15 @@
                 TruthIndexEntry-sourceName TruthIndexEntry-canonicalSourceName
                 TruthIndexEntry-page TruthIndexEntry-dpi TruthIndexEntry-groupCount
                 TruthIndexEntry-truthTime betterTruthIndex
-                fileExists fileIsDirectory fileIsRegular destinationNewFileDelta
+                fileExists fileIsDirectory fileIsRegular safeLocalRegularFile
+                destinationNewFileDelta
                 oldDestinationBytes urlEffectivePort
                 remoteBearerTokenPresent remoteBearerTokenValid
                 remotePinPresent remotePinOrNull remotePinSha256Length
                 remoteRelativePathSafe
                 shouldCompareMoreCompleteTruth)
         (type File)
+        (type Path)
         (type URL)
         (type Int32)
         (extern (fileExistsRaw (file : File)) : Bool
@@ -1586,6 +1591,10 @@
           (kotlin-member-get isDirectory))
         (extern (fileLength (file : File)) : Int
           (kotlin-member-call length))
+        (extern (fileToPath (file : File)) : Path
+          (kotlin-member-call toPath))
+        (extern (pathIsSymbolicLink (path : Path)) : Bool
+          (kotlin-call Files isSymbolicLink))
         (extern (bytesSize (bytes : Bytes)) : Int32
           (kotlin-member-get size))
         (extern (base64Decode (text : String) (flags : Int32)) : Bytes
@@ -1625,6 +1634,9 @@
           (and (fileExists file) (fileIsDirectoryRaw file)))
         (def (fileIsRegular (file : File)) : Bool
           (and (fileExists file) (fileIsFile file)))
+        (def (safeLocalRegularFile (file : File)) : Bool
+          (and (fileIsRegular file)
+               (not (pathIsSymbolicLink (fileToPath file)))))
         (def (destinationNewFileDelta (destination : File)) : Int32
           (if (fileExists destination) (int32 0) (int32 1)))
         (def (oldDestinationBytes (destination : File)) : Int
@@ -8398,7 +8410,7 @@
        "    }"
        ""
        "    private fun validateImportedText(name: String, text: String) {"
-       "        if (name.endsWith(\".jsonl\")) {"
+       "        if (jsonLinesFileName(name)) {"
        "            var lines = 0"
        "            trimmedNonBlankLines(text).forEach { line ->"
        "                lines += 1"
@@ -8586,7 +8598,7 @@
        "            ?: throw IllegalStateException(unableToCreateSyncFolderMessage(name))"
        ""
        "    private fun writeTreeFile(parent: DocumentFile, relativeName: String, source: File) {"
-       "        require(source.isFile && !Files.isSymbolicLink(source.toPath()))"
+       "        require(safeLocalRegularFile(source))"
        "        require(source.length() <= MAX_ZIP_ENTRY_BYTES) { \"Tree export file exceeds byte limit\" }"
        "        val parts = trimmedNonBlankPathParts(relativeName, File.separatorChar, '/')"
        "        require(safeTreePathParts(parts, MAX_ZIP_DEPTH))"
@@ -8699,7 +8711,7 @@
        "    }"
        ""
        "    private fun readLocalText(file: File): String {"
-       "        require(file.isFile && !Files.isSymbolicLink(file.toPath())) { \"Unsafe local file\" }"
+       "        require(safeLocalRegularFile(file)) { \"Unsafe local file\" }"
        "        return file.inputStream().use { readBoundedBytes(it, MAX_ZIP_ENTRY_BYTES).decodeToString() }"
        "    }"
        ""