소스 검색

updating zlib to 1.3.2

El RIDO 3 달 전
부모
커밋
43a729b1f9
11개의 변경된 파일73개의 추가작업 그리고 55개의 파일을 삭제
  1. 1 1
      CHANGELOG.md
  2. 1 1
      js/common.js
  3. BIN
      js/zlib-1.3.1.wasm
  4. 0 0
      js/zlib-1.3.2.mjs
  5. BIN
      js/zlib-1.3.2.wasm
  6. 18 42
      js/zlib.js
  7. 2 1
      lib/Configuration.php
  8. 46 7
      lib/View.php
  9. 2 1
      tpl/bootstrap.php
  10. 2 1
      tpl/bootstrap5.php
  11. 1 1
      tst/Bootstrap.php

+ 1 - 1
CHANGELOG.md

@@ -4,7 +4,7 @@
 * ADDED: Translations for Swedish & Persian
 * CHANGED: Deduplicate JSON error message translations
 * CHANGED: Refactored translation of exception messages
-* CHANGED: Upgrading libraries to: DOMpurify 3.3.2, ip-lib 1.22.0 & polyfill-php80 1.33.0
+* CHANGED: Upgrading libraries to: DOMpurify 3.3.2, ip-lib 1.22.0, polyfill-php80 1.33.0 & zlib 1.3.2
 * FIXED: Some exceptions not getting translated
 * FIXED: Attachment disappears after a "paste" in the message area (#1731)
 * FIXED: The content format is not reset when creating a new document (#1707)

+ 1 - 1
js/common.js

@@ -10,7 +10,7 @@ global.WebCrypto = require('@peculiar/webcrypto').Crypto;
 
 // application libraries to test
 global.$ = global.jQuery = require('./jquery-3.7.1');
-global.zlib = require('./zlib-1.3.1-2').zlib;
+global.zlib = require('./zlib').zlib;
 require('./prettify');
 global.prettyPrint = window.PR.prettyPrint;
 global.prettyPrintOne = window.PR.prettyPrintOne;

BIN
js/zlib-1.3.1.wasm


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
js/zlib-1.3.2.mjs


BIN
js/zlib-1.3.2.wasm


+ 18 - 42
js/zlib-1.3.1-2.js → js/zlib.js

@@ -9,37 +9,22 @@
         const COMPRESSION_LEVEL = 7;
         const NO_ZLIB_HEADER = -1;
         const CHUNK_SIZE = 32 * 1024;
-        const map = {};
-        const memory = new WebAssembly.Memory({
-            initial: 1,
-            maximum: 1024, // 64MB
-        });
-        const env = {
-            memory,
-            writeToJs(ptr, size) {
-                const o = map[ptr];
-                o.onData(new Uint8Array(memory.buffer, dstPtr, size));
-            },
-            _abort: errno => { console.error(`Error: ${errno}`) },
-            _grow: () => { },
-        };
-        const ins = (await WebAssembly.instantiateStreaming(fetch('js/zlib-1.3.1.wasm'), { env })).instance;
-
-        const srcPtr = ins.exports._malloc(CHUNK_SIZE);
-        const dstPtr = ins.exports._malloc(CHUNK_SIZE);
+        const Module = await import('zlib-1.3.2.mjs');
+        Module.map = {};
+        const srcPtr = Module.__malloc(CHUNK_SIZE);
+        const dstPtr = Module.__malloc(CHUNK_SIZE);
 
         class RawDef {
             constructor() {
-                this.zstreamPtr = ins.exports._createDeflateContext(COMPRESSION_LEVEL, NO_ZLIB_HEADER);
-                map[this.zstreamPtr] = this;
+                this.zstreamPtr = Module.__createDeflateContext(COMPRESSION_LEVEL, NO_ZLIB_HEADER);
+                Module.map[this.zstreamPtr] = this;
                 this.offset = 0;
                 this.buff = new Uint8Array(CHUNK_SIZE);
             }
 
             deflate(chunk, flush) {
-                const src = new Uint8Array(memory.buffer, srcPtr, chunk.length);
-                src.set(chunk);
-                ins.exports._deflate(this.zstreamPtr, srcPtr, dstPtr, chunk.length, CHUNK_SIZE, flush);
+                Module.HEAPU8.set(chunk, srcPtr);
+                Module.__deflate(this.zstreamPtr, srcPtr, dstPtr, chunk.length, CHUNK_SIZE, flush);
             }
 
             onData(chunk) {
@@ -53,32 +38,27 @@
             }
 
             destroy() {
-                ins.exports._freeDeflateContext(this.zstreamPtr);
-                delete map[this.zstreamPtr];
+                Module.__freeDeflateContext(this.zstreamPtr);
+                delete Module.map[this.zstreamPtr];
                 this.buff = null;
             }
 
             getBuffer() {
-                const res = new Uint8Array(this.offset);
-                for (let i = 0; i < this.offset; ++i) {
-                    res[i] = this.buff[i];
-                }
-                return res;
+                return Buffer.from(this.buff.buffer, 0, this.offset);
             }
         }
 
         class RawInf {
             constructor() {
-                this.zstreamPtr = ins.exports._createInflateContext(NO_ZLIB_HEADER);
-                map[this.zstreamPtr] = this;
+                this.zstreamPtr = Module.__createInflateContext(NO_ZLIB_HEADER);
+                Module.map[this.zstreamPtr] = this;
                 this.offset = 0;
                 this.buff = new Uint8Array(CHUNK_SIZE);
             }
 
             inflate(chunk) {
-                const src = new Uint8Array(memory.buffer, srcPtr, chunk.length);
-                src.set(chunk);
-                ins.exports._inflate(this.zstreamPtr, srcPtr, dstPtr, chunk.length, CHUNK_SIZE);
+                Module.HEAPU8.set(chunk, srcPtr);
+                Module.__inflate(this.zstreamPtr, srcPtr, dstPtr, chunk.length, CHUNK_SIZE);
             }
 
             onData(chunk) {
@@ -92,17 +72,13 @@
             }
 
             destroy() {
-                ins.exports._freeInflateContext(this.zstreamPtr);
-                delete map[this.zstreamPtr];
+                Module.__freeInflateContext(this.zstreamPtr);
+                delete Module.map[this.zstreamPtr];
                 this.buff = null;
             }
 
             getBuffer() {
-                const res = new Uint8Array(this.offset);
-                for (let i = 0; i < this.offset; ++i) {
-                    res[i] = this.buff[i];
-                }
-                return res;
+                return Buffer.from(this.buff.buffer, 0, this.offset);
             }
         }
 

+ 2 - 1
lib/Configuration.php

@@ -125,7 +125,8 @@ class Configuration
             'js/privatebin.js'       => 'sha512-6SwOJniNN8RBmAK7yCt4ly2qYyH8OALxB74/K1AJgw+YnZgRCfTDVq1qY1K5Y2QCxCODGGTpAjTqQRExzCqV7g==',
             'js/purify-3.3.2.js'     => 'sha512-I6igPVpf3xNghG92mujwqB6Zi3LpUTsni4bRuLnMThEGH6BDbsumv7373+AXHzA4OUlxGsym8ZxKFHy4xjYvkQ==',
             'js/showdown-2.1.0.js'   => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
-            'js/zlib-1.3.1-2.js'     => 'sha512-4gT+v+BkBqdVBbKOO4qKGOAzuay+v1FmOLksS+bMgQ08Oo4xEb3X48Xq1Kv2b4HtiCQA7xq9dFRzxal7jmQI7w==',
+            'js/zlib-1.3.2.mjs'      => 'sha512-rv8vIHS886FB1BwNSDK2ePuAlQ2kjuCKyKfu6R6xrUaBW74XJwUkgBkYwb2Qo48JGcfenzJuJWnj7aunxXkyIw==',
+            'js/zlib.js'             => 'sha512-WrCFRc7+7FdFDhN86LQ0g8GHzwhGIqPJ29NBGu2xM3cqkCC9GSMZf/24dhg6+iQs1xjcnWjandBFIOP7xCBUpg==',
         ),
     );
 

+ 46 - 7
lib/View.php

@@ -62,6 +62,49 @@ class View
         include $path;
     }
 
+    /**
+     * get cache buster query string
+     *
+     * if the file isn't versioned (ends in a digit), adds our own version as a query string
+     *
+     * @access private
+     * @param  string $file
+     */
+    private function _getCacheBuster($file)
+    {
+        //
+        if ((bool) preg_match('#[0-9]\.m?js$#', (string) $file)) {
+            return '';
+        }
+        return '?' . rawurlencode($this->_variables['VERSION']);
+    }
+
+    /**
+     * get SRI hash for given file
+     *
+     * @access private
+     * @param  string $file
+     */
+    private function _getSri($file)
+    {
+        if (array_key_exists($file, $this->_variables['SRI'])) {
+            return ' integrity="' . $this->_variables['SRI'][$file] . '"';
+        }
+        return '';
+    }
+
+    /**
+     * echo module preload link tag incl. SRI hash for given script file
+     *
+     * @access private
+     * @param  string $file
+     */
+    private function _linkTag($file)
+    {
+        echo '<link rel="modulepreload" href="', $file,
+            $this->_getCacheBuster($file), '"', $this->_getSri($file), ' />', PHP_EOL;
+    }
+
     /**
      * echo script tag incl. SRI hash for given script file
      *
@@ -71,13 +114,9 @@ class View
      */
     private function _scriptTag($file, $attributes = '')
     {
-        $sri = array_key_exists($file, $this->_variables['SRI']) ?
-            ' integrity="' . $this->_variables['SRI'][$file] . '"' : '';
-        // if the file isn't versioned (ends in a digit), add our own version
-        $cacheBuster = (bool) preg_match('#[0-9]\.js$#', (string) $file) ?
-            '' : '?' . rawurlencode($this->_variables['VERSION']);
         echo '<script ', $attributes,
-        ' type="text/javascript" data-cfasync="false" src="', $file,
-        $cacheBuster, '"', $sri, ' crossorigin="anonymous"></script>', PHP_EOL;
+            ' type="text/javascript" data-cfasync="false" src="', $file,
+            $this->_getCacheBuster($file), '"', $this->_getSri($file),
+            ' crossorigin="anonymous"></script>', PHP_EOL;
     }
 }

+ 2 - 1
tpl/bootstrap.php

@@ -42,6 +42,7 @@ if ($SYNTAXHIGHLIGHTING) :
 endif;
 ?>
 		<noscript><link type="text/css" rel="stylesheet" href="css/noscript.css" /></noscript>
+		<?php $this->_linkTag('js/zlib-1.3.2.mjs'); ?>
 		<?php $this->_scriptTag('js/jquery-3.7.1.js', 'defer'); ?>
 <?php
 if ($QRCODE) :
@@ -50,7 +51,7 @@ if ($QRCODE) :
 <?php
 endif;
 ?>
-		<?php $this->_scriptTag('js/zlib-1.3.1-2.js', 'defer'); ?>
+		<?php $this->_scriptTag('js/zlib.js', 'defer'); ?>
 		<?php $this->_scriptTag('js/base-x-5.0.1.js', 'defer'); ?>
 		<?php $this->_scriptTag('js/bootstrap-3.4.1.js', 'defer'); ?>
 <?php

+ 2 - 1
tpl/bootstrap5.php

@@ -25,6 +25,7 @@ if ($SYNTAXHIGHLIGHTING) :
 endif;
 ?>
 		<noscript><link type="text/css" rel="stylesheet" href="css/noscript.css" /></noscript>
+		<?php $this->_linkTag('js/zlib-1.3.2.mjs'); ?>
 		<?php $this->_scriptTag('js/jquery-3.7.1.js', 'defer'); ?>
 <?php
 if ($QRCODE) :
@@ -33,7 +34,7 @@ if ($QRCODE) :
 <?php
 endif;
 ?>
-		<?php $this->_scriptTag('js/zlib-1.3.1-2.js', 'defer'); ?>
+		<?php $this->_scriptTag('js/zlib.js', 'defer'); ?>
 		<?php $this->_scriptTag('js/base-x-5.0.1.js', 'defer'); ?>
 		<?php $this->_scriptTag('js/bootstrap-5.3.8.js', 'defer'); ?>
 		<?php $this->_scriptTag('js/dark-mode-switch.js', 'defer'); ?>

+ 1 - 1
tst/Bootstrap.php

@@ -341,7 +341,7 @@ class Helper
      */
     public static function updateSubresourceIntegrity(): void
     {
-        foreach (new GlobIterator(PATH . 'js' . DIRECTORY_SEPARATOR . '*.js') as $file) {
+        foreach (new GlobIterator(PATH . 'js' . DIRECTORY_SEPARATOR . '*.*js') as $file) {
             if ($file->getBasename() === 'common.js' || $file->getBasename() === 'eslint.config.js') {
                 continue; // ignore JS unit test bootstrap
             }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.