Title: Decrypting a zero-length array with SubtleCrypto triggers Assertion failures · Issue #38883 · nodejs/node · GitHub
Open Graph Title: Decrypting a zero-length array with SubtleCrypto triggers Assertion failures · Issue #38883 · nodejs/node
X Title: Decrypting a zero-length array with SubtleCrypto triggers Assertion failures · Issue #38883 · nodejs/node
Description: Version: v16.2.0 Platform: Darwin shinji 20.6.0 Darwin Kernel Version 20.6.0: Mon May 10 03:15:35 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro16,2 Darwin Subsystem: webcrypto (specifically SubtleCrypto) Wha...
Open Graph Description: Version: v16.2.0 Platform: Darwin shinji 20.6.0 Darwin Kernel Version 20.6.0: Mon May 10 03:15:35 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro16,2 Darwin Subsystem: w...
X Description: Version: v16.2.0 Platform: Darwin shinji 20.6.0 Darwin Kernel Version 20.6.0: Mon May 10 03:15:35 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro16,2 Darwin Subsystem: w...
Opengraph URL: https://github.com/nodejs/node/issues/38883
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Decrypting a zero-length array with SubtleCrypto triggers Assertion failures","articleBody":"\u003c!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or output of `\"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { \"x64\" } else { \"x86\" })\"` in PowerShell console (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n--\u003e\r\n\r\n* **Version**: v16.2.0\r\n* **Platform**: `Darwin shinji 20.6.0 Darwin Kernel Version 20.6.0: Mon May 10 03:15:35 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro16,2 Darwin`\r\n* **Subsystem**: webcrypto (specifically SubtleCrypto)\r\n\r\n### What steps will reproduce the bug?\r\n\r\nAttempting to decrypt a zero-length array crashes node completely. There are two ways to trigger this.\r\n\r\nThe first encrypts a zero length array and then attempts to decrypt that same data:\r\n```\r\nconst crypto = require('crypto').webcrypto;\r\ncrypto.subtle.importKey('raw', new Uint8Array(32), {name: 'AES-GCM'}, false, ['encrypt','decrypt'])\r\n .then(k =\u003e\r\n crypto.subtle.encrypt({name: 'AES-GCM', iv: new Uint8Array(12)}, k, new Uint8Array(0))\r\n .then(e =\u003e\r\n crypto.subtle.decrypt({name: 'AES-GCM', iv: new Uint8Array(12)}, k, e)\r\n )\r\n )\r\n .then(v =\u003e console.log(v));\r\n```\r\n\r\nThe second simply decrypts a zero length data array:\r\n```\r\nconst crypto = require('crypto').webcrypto;\r\ncrypto.subtle.importKey('raw', new Uint8Array(32), {name: 'AES-GCM'}, false, ['encrypt','decrypt'])\r\n .then(k =\u003e crypto.subtle.decrypt({name: 'AES-GCM', iv: new Uint8Array(12)}, k, new Uint8Array(0)))\r\n .then(v =\u003e console.log(v));\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nEvery time.\r\n\r\n### What is the expected behavior?\r\n\r\nThe `decrypt` call should produce a zero-length array in the first case, and fail in the second (chrome rejects with `The provided data is too small`).\r\n\r\n### What do you see instead?\r\n\r\nNode crashes. The two snippets trigger different errors.\r\n\r\nFirst:\r\n```\r\nnode[51088]: ../src/crypto/crypto_cipher.h:261:virtual v8::Maybe\u003cbool\u003e node::crypto::CipherJob\u003cnode::crypto::AESCipherTraits\u003e::ToResult(v8::Local\u003cv8::Value\u003e *, v8::Local\u003cv8::Value\u003e *) [CipherTraits = node::crypto::AESCipherTraits]: Assertion `!errors-\u003eEmpty()' failed.\r\n 1: 0x105ac3832 node::Abort() [/usr/local/bin/node]\r\n 2: 0x105ac36be node::AppendExceptionLine(node::Environment*, v8::Local\u003cv8::Value\u003e, v8::Local\u003cv8::Message\u003e, node::ErrorHandlingMode) [/usr/local/bin/node]\r\n 3: 0x105b93582 node::crypto::CipherJob\u003cnode::crypto::AESCipherTraits\u003e::DoThreadPoolWork() [/usr/local/bin/node]\r\n 4: 0x105b93309 node::crypto::CryptoJob\u003cnode::crypto::AESCipherTraits\u003e::AfterThreadPoolWork(int) [/usr/local/bin/node]\r\n 5: 0x106345d74 uv__work_done [/usr/local/bin/node]\r\n 6: 0x106349528 uv__async_io [/usr/local/bin/node]\r\n 7: 0x106359662 uv__io_poll [/usr/local/bin/node]\r\n 8: 0x10634995e uv_run [/usr/local/bin/node]\r\n 9: 0x105a12624 node::SpinEventLoop(node::Environment*) [/usr/local/bin/node]\r\n10: 0x105afbd35 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [/usr/local/bin/node]\r\n11: 0x105a9ab72 node::Start(int, char**) [/usr/local/bin/node]\r\n12: 0x7fff20348f5d start [/usr/lib/system/libdyld.dylib]\r\n13: 0x1\r\nAbort trap: 6\r\n```\r\n\r\nSecond:\r\n```\r\nnode[51123]: ../src/crypto/crypto_aes.cc:92:node::crypto::WebCryptoCipherStatus node::crypto::(anonymous namespace)::AES_Cipher(node::Environment *, node::crypto::KeyObjectData *, node::crypto::WebCryptoCipherMode, const node::crypto::AESCipherConfig \u0026, const node::crypto::ByteSource \u0026, node::crypto::ByteSource *): Assertion `params.tag' failed.\r\n 1: 0x10d74e832 node::Abort() [/usr/local/bin/node]\r\n 2: 0x10d74e6be node::AppendExceptionLine(node::Environment*, v8::Local\u003cv8::Value\u003e, v8::Local\u003cv8::Message\u003e, node::ErrorHandlingMode) [/usr/local/bin/node]\r\n 3: 0x10d81ccf3 node::crypto::AES::Initialize(node::Environment*, v8::Local\u003cv8::Object\u003e) [/usr/local/bin/node]\r\n 4: 0x10d81e5d6 node::crypto::CipherJob\u003cnode::crypto::AESCipherTraits\u003e::DoThreadPoolWork() [/usr/local/bin/node]\r\n 5: 0x10dfd1128 worker [/usr/local/bin/node]\r\n 6: 0x7fff2032d8fc _pthread_start [/usr/lib/system/libsystem_pthread.dylib]\r\n 7: 0x7fff20329443 thread_start [/usr/lib/system/libsystem_pthread.dylib]\r\nAbort trap: 6\r\n```\r\n### Additional information\r\n\r\nThese inputs are far from normal, but I figure node should never _crash_.\r\n\r\nThe project I work on has property tests involving webcrypto. We've been using `node-webcrypto-ossl` to run these tests for months; we thought it might be nice to switch to the new built-in webcrypto instead. Our property tests are designed to throw all sorts of invalid values at our own code - but it turns out they throw invalid values at the webcrypto API as well.","author":{"url":"https://github.com/TheSpyder","@type":"Person","name":"TheSpyder"},"datePublished":"2021-06-01T07:00:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/38883/node/issues/38883"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ef67a947-7995-7257-4116-c4d6985121f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8114:3B3BAC:14A20E1:1E16B9F:6A4E4A25 |
| html-safe-nonce | 94cd1dc9ffe83c590750decc683d5cc9495e1181a3ddaece27e4545c2338651b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTE0OjNCM0JBQzoxNEEyMEUxOjFFMTZCOUY6NkE0RTRBMjUiLCJ2aXNpdG9yX2lkIjoiMjUzNjY1NTg5MjM4NTgxNzk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5b3f089aa8cc1d6a4bb2f6b873bf199ed767bed9640d8aa8a83023c3d81a625a |
| hovercard-subject-tag | issue:907966424 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/38883/issue_layout |
| twitter:image | https://opengraph.githubassets.com/45fdb043a8054cbaadd146d74edc995fcc047d6653dbc96b14289b066b22f856/nodejs/node/issues/38883 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/45fdb043a8054cbaadd146d74edc995fcc047d6653dbc96b14289b066b22f856/nodejs/node/issues/38883 |
| og:image:alt | Version: v16.2.0 Platform: Darwin shinji 20.6.0 Darwin Kernel Version 20.6.0: Mon May 10 03:15:35 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro16,2 Darwin Subsystem: w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TheSpyder |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e8506f6d0538364886e3f0153c154c410965e70d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width