tutao / tutanota

Tuta is an email service with a strong focus on security and privacy that lets you encrypt emails, contacts and calendar entries on all your devices.
https://tuta.com
GNU General Public License v3.0
6.11k stars 526 forks source link

wasm2js build error : stdout maxBuffer length exceeded #7854

Closed gen2-sys-it closed 2 weeks ago

gen2-sys-it commented 2 weeks ago

Bug in web app

Describe the bug (Running Ubuntu 20.04.6 LTS) When building the webapp from scratch using the build instructions in the latest version (250.241025.0), the following build error appears when dealing with liboqs: Build error: RangeError [PLUGIN_ERROR]: Could not load wasm-fallback:liboqs.wasm (imported by wasm-loader:liboqs.wasm): stdout maxBuffer length exceeded

To Reproduce Steps to reproduce the behavior: Follow the build instructions... as they are written. (https://github.com/tutao/tutanota/blob/master/doc/BUILDING.md)

The build process works perfectly up until "node webapp prod" is run..

Screenshots

[1068 tutanota-250.241025.0]$ node webapp prod
Building app mail
started cleaning 0.004
bundling polyfill 0.012
[plugin typescript] @rollup/plugin-typescript: outputToFilesystem option is defaulting to true.
started copying images 36.394
started bundling 36.426
wasm build: emcc \
        "phc-winner-argon2/src/argon2.c" "phc-winner-argon2/src/core.c" "phc-winner-argon2/src/ref.c" "phc-winner-argon2/src/blake2/blake2b.c" \
        -I "phc-winner-argon2/include" \
        -DARGON2_NO_THREADS \
        -flto \
        -O3 \
        --no-entry \
        -s TOTAL_MEMORY=48MB \
        -s EXPORTED_FUNCTIONS="['_argon2id_hash_raw', '_malloc', '_free']" \
        -o ../../build/wasm/argon2.wasm

wasm build: emcc \
        "liboqs/src/kem/kem.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/kem.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/verify.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/indcpa.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/symmetric-shake.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/poly.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/polyvec.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/cbd.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/ntt.c" "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref/reduce.c" "liboqs/src/kem/kyber/kem_kyber_1024.c" "liboqs/src/common/pqclean_shims/fips202.c" "liboqs/src/common/sha3/xkcp_sha3.c" "liboqs/src/common/sha3/xkcp_low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c" "liboqs/src/common/common.c" "../../packages/tutanota-crypto/lib/encryption/Liboqs/rand.c" "../../packages/tutanota-crypto/lib/encryption/Liboqs/exit.c" \
        -I "include" \
        -I "liboqs/src/kem/kyber/pqcrystals-kyber_kyber1024_ref" \
        -I "liboqs/src/common/pqclean_shims" \
        -DOQS_VERSION_TEXT=\"tutakyber\" \
        -DOQS_ENABLE_KEM_kyber_1024=1 \
        -DOQS_ENABLE_KEM_KYBER=1 \
        -DOQS_DIST_BUILD=1 \
        -DKYBER_K=4 \
        -flto \
        -O3 \
        -s STANDALONE_WASM \
        --no-entry \
        -s TOTAL_MEMORY=48MB \
        -s EXPORTED_FUNCTIONS="['_OQS_KEM_new', '_OQS_KEM_free', '_OQS_KEM_keypair', '_OQS_KEM_encaps', '_OQS_KEM_decaps', '_TUTA_inject_entropy', '_malloc', '_free']" \
        -o ../../build/wasm/liboqs.wasm

Build error: RangeError [PLUGIN_ERROR]: Could not load wasm-fallback:liboqs.wasm (imported by wasm-loader:liboqs.wasm): stdout maxBuffer length exceeded
    at Socket.onChildStdout (node:child_process:490:14)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23) {
  code: 'PLUGIN_ERROR',
  cmd: 'wasm2js build/wasm/liboqs.wasm -O3',
  stdout: '(module\n' +
    ' (type $i32_=>_none (func (param i32)))\n' +
    ' (type $i32_i32_i32_=>_none (func (param i32 i32 i32)))\n' +
    ' (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))\n' +
    ' (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))\n' +
    ' (type $i32_=>_i32 (func (param i32) (result i32)))\n' +
    ' (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))\n' +
    ' (type $i32_i32_=>_none (func (param i32 i32)))\n' +
    ' (type $i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32) (result i32)))\n' +
    ' (type $none_=>_none (func))\n' +
    ' (type $none_=>_i32 (func (result i32)))\n' +
    ' (memory $0 2048 2048)\n' +
    ' (data (i32.const 1024) "https://github.com/pq-crystals/kyber/commit/28413dfbf523fdde181246451c2bd77199c0f7ff\\00Classic-McEliece-6960119f\\00Classic-McEliece-6688128f\\00Classic-McEliece-8192128f\\00Classic-McEliece-460896f\\00Classic-McEliece-348864f\\00Classic-McEliece-6960119\\00Kyber768\\00Classic-McEliece-6688128\\00Classic-McEliece-8192128\\00HQC-128\\00Classic-McEliece-460896\\00HQC-256\\00BIKE-L5\\00Classic-McEliece-348864\\00Kyber1024\\00BIKE-L3\\00HQC-192\\00Kyber512\\00BIKE-L1\\00\\00\\00\\00\\00\\ec\\fb\\n\\fd\\99\\fe\\13\\fa\\d5\\05\\8e\\05\\1f\\01\\ca\\00U\\ffn\\02)\\06\\b6\\00\\c2\\03N\\fb>\\fa\\bc\\05=\\02\\d3\\fa\\08\\01\\7f\\01\\c3\\fc\\b2\\05\\be\\f9~\\ffW\\fd\\f9\\03\\dc\\02`\\02\\fa\\f9\\9b\\013\\ff\\dd\\f9\\c7\\04\\8c\\02\\d8\\fd\\f7\\03\\f3\\fa\\d3\\05\\e6\\fe\\f8\\f9\\04\\02\\f8\\ff\\c0\\fef\\fd\\ae\\f9v\\fb~\\00\\bd\\05\\ab\\fc\\a6\\ff\\f1\\fe>\\03k\\00s\\fa\\t\\ffI\\fcr\\fe\\c1\\03\\1c\\fa+\\fd\\c0\\01\\d7\\fb\\a5\\02\\05\\fb\\b1\\fb\\ae\\01+\\02K\\03\\1d\\fbg\\03\\0e\\06i\\00\\a6\\01K\\02\\b1\\00\\15\\ff\\dd\\fe4\\fe&\\06u\\06\\n\\ff\\n\\03\\87\\04m\\ff\\f7\\fc\\cb\\05\\a6\\fd_\\04\\ca\\f9\\84\\02\\98\\fc]\\01\\a2\\01I\\01d\\ff\\b5\\ff1\\03I\\04[\\02b\\02*\\05\\fb\\faG\\fa\\80\\01A\\fbx\\ff\\c2\\04\\c9\\fa\\96\\fc\\dc\\00]\\fb\\85\\f9_\\fb\\06\\fa\\02\\fb\\1a\\03\\1a\\fa\\aa\\fc\\9a\\fc\\de\\01\\94\\ff\\cc\\fe\\e4\\03\\df\\03\\be\\03L\\fa\\f2\\05\\\\\\06")\n' +
    ' (data (i32.const 1696) "\\f0\\08\\01\\00\\06\\00\\00\\00@")\n' +
    ' (table $0 7 7 funcref)\n' +
    ' (elem (i32.const 1) $0 $27 $28 $29 $33 $32)\n' +
    ' (global $global$0 (mut i32) (i32.const 67824))\n' +
    ' (export "memory" (memory $0))\n' +
    ' (export "OQS_KEM_new" (func $8))\n' +
    ' (export "OQS_KEM_keypair" (func $10))\n' +
    ' (export "OQS_KEM_encaps" (func $11))\n' +
    ' (export "OQS_KEM_decaps" (func $12))\n' +
    ' (export "OQS_KEM_free" (func $13))\n' +
    ' (export "malloc" (func $4))\n' +
    ' (export "free" (func $5))\n' +
    ' (export "TUTA_inject_entropy" (func $37))\n' +
    ' (export "_initialize" (func $0))\n' +
    ' (export "__indirect_function_table" (table $0))\n' +
    ' (export "_emscripten_stack_restore" (func $6))\n' +
    ' (export "emscripten_stack_get_current" (func $7))\n' +
    ' (func $0 (; 0 ;)\n' +
    ' )\n' +
    ' (func $1 (; 1 ;) (param $0 i32) (result i32)\n' +
    '  (local $1 i32)\n' +
    '  (local $2 i32)\n' +
    '  (local $3 i32)\n' +
    '  (i32.store8\n' +
    '   (local.get $0)\n' +
 ...
 continued output
 ...
   '     (i32.store offset=40\n' +
    '      (local.get $2)\n' +
    '      ('... 1038576 more characters,
  stderr: '[wasm-validator error in function 17] unexpected false: all used features should be allowed, on \n' +
    '[i32] (i32.extend16_s\n' +
    ' [i32] (i32.add\n' +
    '  [i32] (i32.and\n' +
    '   [i32] (i32.shr_u\n' +
    '    [i32] (local.tee $8\n' +
    '     [i32] (i32.load16_s offset=14\n' +
    '      [i32] (local.get $0)\n' +
    '     )\n' +
    '    )\n' +
    '    [i32] (i32.const 15)\n' +
    '   )\n' +
    '   [i32] (i32.const 3329)\n' +
    '  )\n' +
    '  [i32] (local.get $8)\n' +
    ' )\n' +
    ')\n' +
    '[wasm-validator error in function 17] unexpected false: all used features should be allowed, on \n' +
    '[i32] (i32.extend16_s\n' +
    ' [i32] (i32.add\n' +
    '  [i32] (i32.and\n' +
    '   [i32] (i32.shr_u\n' +
    '    [i32] (local.tee $0\n' +
    '     [i32] (i32.load16_s offset=12\n' +
    '      [i32] (local.get $0)\n' +
    '     )\n' +
    '    )\n' +
    '    [i32] (i32.const 15)\n' +
    '   )\n' +
    '   [i32] (i32.const 3329)\n' +
    '  )\n' +
    '  [i32] (local.get $0)\n' +
    ' )\n' +
    ')\n' +
    '[wasm-validator error in function 17] unexpected false: all used features should be allowed, on \n' +
    '[i32] (i32.extend16_s\n' +
 ...
 continued output

 ...
  '   [i32] (i32.load'... 8241 more characters,
  pluginCode: 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER',
  plugin: 'wasm',
  hook: 'load',
  watchFiles: [
  ...
 continued output
  ...
  ... 744 more items
  ]
}
gen2-sys-it commented 2 weeks ago

This has been fixed by upgrading binaryen (the package that contains wasm2js) to version 119. (https://github.com/WebAssembly/binaryen)

The version that comes with Ubuntu 20.04 is version 91.. and can't handle the latest versions of nota.