Use typed SSD connection length checks

ober

d023cccd7973d6db74ce02f531987e745a5eacdf

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 2640318..0cbd7ca 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -5439,16 +5439,21 @@
     (typed-kotlin-file "com/sfb/ssdreview/NetworkSafety.kt"
       (kotlin-imports (java io InputStream)
                       (java io BufferedInputStream)
+                      (java net URLConnection)
                       (java util zip GZIPInputStream))
       (typed-library (com sfb ssdreview)
         (export normalizeRemoteEndpointValue normalizeRemoteEndpoint urlEncode
                 contentEncodingIsGzip responseInputStream
+                connectionContentLengthExceedsLimit
                 localTruthHttpAllowed)
         (type InputStream)
+        (type URLConnection)
         (extern (bufferedInputStream (input : InputStream)) : InputStream
           (kotlin-call java io BufferedInputStream))
         (extern (gzipInputStream (input : InputStream)) : InputStream
           (kotlin-call java util zip GZIPInputStream))
+        (extern (connectionContentLength (connection : URLConnection)) : Int
+          (kotlin-member-get contentLengthLong))
         (def (normalizeRemoteEndpointValue (value : String) (defaultEndpoint : String)) : String
           (let ((trimmed (string-trim value)))
             (let ((base (if (string-blank? trimmed) defaultEndpoint trimmed)))
@@ -5476,6 +5481,9 @@
           (if (contentEncodingIsGzip contentEncoding)
               (gzipInputStream (bufferedInputStream raw))
               raw))
+        (def (connectionContentLengthExceedsLimit (connection : URLConnection)
+                                                  (limit : Int)) : Bool
+          (> (connectionContentLength connection) limit))
         (def (localTruthHttpAllowed (host : String)) : Bool
           (let ((lower (string-lowercase host)))
             (if (or (or (equal? lower "localhost")
@@ -8271,7 +8279,7 @@
        "    }"
        ""
        "    private fun readResponseText(connection: HttpsURLConnection): String {"
-       "        if (connection.contentLengthLong > MAX_HTTP_COMPRESSED_BYTES) {"
+       "        if (connectionContentLengthExceedsLimit(connection, MAX_HTTP_COMPRESSED_BYTES)) {"
        "            throw IllegalStateException(\"HTTP response exceeds compressed-byte limit\")"
        "        }"
        "        val raw = LimitedInputStream(connection.inputStream, MAX_HTTP_COMPRESSED_BYTES)"
@@ -8455,7 +8463,7 @@
        "                connection.errorStream?.close()"
        "                throw IllegalStateException(httpStatusMessage(code))"
        "            }"
-       "            if (connection.contentLengthLong > MAX_REMOTE_ZIP_BYTES) {"
+       "            if (connectionContentLengthExceedsLimit(connection, MAX_REMOTE_ZIP_BYTES)) {"
        "                throw IllegalStateException(\"Remote ZIP exceeds compressed-byte limit\")"
        "            }"
        "            return connection.inputStream.use { importZip(it) }"