]> git.plutz.net Git - rigidfind/commitdiff
use temp files when unzipping documents
authorPaul Hänsch <paul@plutz.net>
Tue, 5 Mar 2024 00:42:07 +0000 (01:42 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 5 Mar 2024 00:42:07 +0000 (01:42 +0100)
index.cgi

index 9ba696abe827ad71aeafd48f8bc178e96905d575..0078a2f8f1837201ae7fc7a19324cd0fe01d4818 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -9,7 +9,7 @@
 debug "$REQUEST_METHOD $REQUEST_URI    $SERVER_PROTOCOL        $_DATE"
 
 ingest() {
-  local J="$1"
+  local J="$1" ztmp="${TMP:-/tmp}/zipfile_$$.zip"
 
   # json_get "$J" title
   # json_get "$J" parts.comments
@@ -39,24 +39,28 @@ ingest() {
       | sed 's;<[^>]*>;;g'
       ;;
     *.docx)
-      printf %s "$content" |base64 -d \
-      | unzip -qc /dev/stdin word/document.xml \
+      printf %s "$content" |base64 -d >"$ztmp"
+      unzip -qc "$ztmp" word/document.xml \
       | head -c 128M | sed 's;<[^>]*>;;g'
+      rm -- "$ztmp"
       ;;
     *.xlsx)
-      printf %s "$content" |base64 -d \
-      | unzip -qc /dev/stdin xl/sharedStrings.xml \
+      printf %s "$content" |base64 -d >"$ztmp"
+      unzip -qc "$ztmp" xl/sharedStrings.xml \
       | head -c 128M | sed 's;<[^>]*>; ;g'
+      rm -- "$ztmp"
       ;;
     *.odt)
-      printf %s "$content" |base64 -d \
-      | unzip -qc /dev/stdin content.xml \
+      printf %s "$content" |base64 -d >"$ztmp"
+      unzip -qc "$ztmp" content.xml \
       | head -c 128M | sed 's;<[^>]*>;;g'
+      rm -- "$ztmp"
       ;;
     *.ods|*.odp)
-      printf %s "$content" |base64 -d \
-      | unzip -qc /dev/stdin content.xml \
+      printf %s "$content" |base64 -d >"$ztmp"
+      unzip -qc "$ztmp" content.xml \
       | head -c 128M | sed 's;<[^>]*>; ;g'
+      rm -- "$ztmp"
       ;;
     *):;;
   esac