Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string_decoder: fix crash when calling __proto__.write() using C++ #42061

Conversation

RaisinTen
Copy link
Contributor

This makes the function throw an exception from C++ instead of crashing.

Fixes: #41949
Signed-off-by: Darshan Sen raisinten@gmail.com

This makes the function throw an exception from C++ instead of crashing.

Fixes: nodejs#41949
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Feb 20, 2022
@RaisinTen
Copy link
Contributor Author

RaisinTen commented Feb 20, 2022

string_decoder benchmark: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1096/

                                                                                            confidence improvement accuracy (*)    (**)   (***)
string_decoder/string-decoder-create.js n=25000000 encoding='ascii'                                         0.39 %       ±1.35%  ±1.80%  ±2.34%
string_decoder/string-decoder-create.js n=25000000 encoding='AscII'                                         0.61 %       ±2.58%  ±3.46%  ±4.55%
string_decoder/string-decoder-create.js n=25000000 encoding='base64'                                       -1.24 %       ±2.57%  ±3.42%  ±4.46%
string_decoder/string-decoder-create.js n=25000000 encoding='ucs2'                                   *     -2.27 %       ±2.17%  ±2.91%  ±3.84%
string_decoder/string-decoder-create.js n=25000000 encoding='UTF-16LE'                             ***      4.62 %       ±2.11%  ±2.81%  ±3.66%
string_decoder/string-decoder-create.js n=25000000 encoding='utf-8'                                         1.99 %       ±2.55%  ±3.42%  ±4.51%
string_decoder/string-decoder-create.js n=25000000 encoding='utf8'                                          4.58 %       ±4.90%  ±6.54%  ±8.55%
string_decoder/string-decoder-create.js n=25000000 encoding='UTF-8'                                         0.50 %       ±2.69%  ±3.58%  ±4.66%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=1024 encoding='ascii'                        3.87 %       ±4.44%  ±5.94%  ±7.81%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=1024 encoding='base64-ascii'                 0.53 %       ±7.08%  ±9.42% ±12.27%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=1024 encoding='base64-utf8'                  2.41 %       ±8.12% ±10.81% ±14.07%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=1024 encoding='utf16le'                      2.95 %       ±4.05%  ±5.44%  ±7.19%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=1024 encoding='utf8'                ***     -2.33 %       ±1.28%  ±1.73%  ±2.29%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=128 encoding='ascii'                        -1.13 %       ±4.31%  ±5.79%  ±7.65%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=128 encoding='base64-ascii'                  2.83 %       ±7.50%  ±9.98% ±12.99%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=128 encoding='base64-utf8'                   7.01 %       ±9.64% ±12.83% ±16.70%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=128 encoding='utf16le'                       0.38 %       ±3.49%  ±4.66%  ±6.08%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=128 encoding='utf8'                 ***     -5.10 %       ±2.15%  ±2.86%  ±3.73%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=32 encoding='ascii'                          5.09 %       ±7.01%  ±9.42% ±12.47%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=32 encoding='base64-ascii'                  -3.95 %       ±6.23%  ±8.34% ±10.95%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=32 encoding='base64-utf8'                    1.87 %       ±5.88%  ±7.82% ±10.18%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=32 encoding='utf16le'                       -2.02 %       ±3.16%  ±4.25%  ±5.60%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=32 encoding='utf8'                          -0.72 %       ±2.17%  ±2.90%  ±3.80%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=4096 encoding='ascii'                        1.26 %       ±1.70%  ±2.28%  ±3.00%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=4096 encoding='base64-ascii'                 2.18 %       ±8.22% ±10.94% ±14.24%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=4096 encoding='base64-utf8'                  0.54 %       ±7.66% ±10.19% ±13.27%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=4096 encoding='utf16le'                     -0.08 %       ±1.32%  ±1.76%  ±2.29%
string_decoder/string-decoder.js n=2500000 chunkLen=1024 inLen=4096 encoding='utf8'                ***     -2.51 %       ±1.14%  ±1.53%  ±2.01%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=1024 encoding='ascii'                         -0.82 %       ±1.22%  ±1.63%  ±2.14%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=1024 encoding='base64-ascii'                  -1.50 %       ±2.09%  ±2.79%  ±3.65%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=1024 encoding='base64-utf8'                   -1.65 %       ±2.89%  ±3.85%  ±5.03%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=1024 encoding='utf16le'               ***     -1.20 %       ±0.36%  ±0.48%  ±0.63%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=1024 encoding='utf8'                          -0.51 %       ±1.09%  ±1.45%  ±1.89%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=128 encoding='ascii'                           0.15 %       ±1.13%  ±1.50%  ±1.96%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=128 encoding='base64-ascii'                   -2.44 %       ±4.56%  ±6.08%  ±7.92%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=128 encoding='base64-utf8'                     2.24 %       ±5.19%  ±6.92%  ±9.03%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=128 encoding='utf16le'                 **     -2.79 %       ±1.86%  ±2.49%  ±3.29%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=128 encoding='utf8'                           -1.07 %       ±1.60%  ±2.13%  ±2.79%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=32 encoding='ascii'                     *     -2.13 %       ±1.96%  ±2.63%  ±3.46%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=32 encoding='base64-ascii'                    -0.83 %       ±5.45%  ±7.26%  ±9.45%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=32 encoding='base64-utf8'                      1.35 %       ±4.80%  ±6.39%  ±8.32%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=32 encoding='utf16le'                         -0.62 %       ±1.56%  ±2.08%  ±2.71%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=32 encoding='utf8'                            -1.91 %       ±2.85%  ±3.80%  ±4.97%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=4096 encoding='ascii'                  **     -0.74 %       ±0.52%  ±0.70%  ±0.91%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=4096 encoding='base64-ascii'                  -0.86 %       ±2.44%  ±3.26%  ±4.27%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=4096 encoding='base64-utf8'                   -0.52 %       ±1.74%  ±2.31%  ±3.01%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=4096 encoding='utf16le'                       -0.12 %       ±0.64%  ±0.85%  ±1.11%
string_decoder/string-decoder.js n=2500000 chunkLen=16 inLen=4096 encoding='utf8'                  ***     -1.07 %       ±0.59%  ±0.79%  ±1.03%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=1024 encoding='ascii'                         0.36 %       ±1.68%  ±2.23%  ±2.90%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=1024 encoding='base64-ascii'                  7.68 %      ±11.07% ±14.73% ±19.17%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=1024 encoding='base64-utf8'                   5.03 %      ±10.32% ±13.73% ±17.88%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=1024 encoding='utf16le'                *     -1.34 %       ±1.33%  ±1.77%  ±2.31%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=1024 encoding='utf8'                 ***     -3.27 %       ±0.97%  ±1.31%  ±1.73%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=128 encoding='ascii'                         -1.83 %       ±6.57%  ±8.76% ±11.43%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=128 encoding='base64-ascii'                   1.01 %       ±9.20% ±12.25% ±15.96%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=128 encoding='base64-utf8'                    0.62 %       ±8.32% ±11.06% ±14.40%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=128 encoding='utf16le'                       -3.00 %       ±6.66%  ±8.88% ±11.58%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=128 encoding='utf8'                  ***     -3.97 %       ±1.90%  ±2.55%  ±3.37%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=32 encoding='ascii'                          -3.69 %       ±6.36%  ±8.57% ±11.34%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=32 encoding='base64-ascii'                   -0.59 %       ±4.87%  ±6.48%  ±8.45%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=32 encoding='base64-utf8'                     5.64 %       ±5.98%  ±7.97% ±10.38%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=32 encoding='utf16le'                        -6.51 %       ±8.32% ±11.11% ±14.53%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=32 encoding='utf8'                           -3.20 %       ±4.35%  ±5.81%  ±7.59%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=4096 encoding='ascii'                        -0.32 %       ±0.98%  ±1.31%  ±1.71%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=4096 encoding='base64-ascii'           *     -9.43 %       ±8.49% ±11.30% ±14.71%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=4096 encoding='base64-utf8'                  -1.90 %       ±9.20% ±12.24% ±15.94%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=4096 encoding='utf16le'                *     -0.93 %       ±0.80%  ±1.07%  ±1.40%
string_decoder/string-decoder.js n=2500000 chunkLen=256 inLen=4096 encoding='utf8'                  **     -2.03 %       ±1.37%  ±1.85%  ±2.45%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=1024 encoding='ascii'                         -0.13 %       ±0.60%  ±0.80%  ±1.04%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=1024 encoding='base64-ascii'                  -0.35 %       ±0.90%  ±1.21%  ±1.58%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=1024 encoding='base64-utf8'                   -0.62 %       ±6.03%  ±8.02% ±10.44%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=1024 encoding='utf16le'                       -0.42 %       ±0.79%  ±1.05%  ±1.37%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=1024 encoding='utf8'                  ***     -2.30 %       ±1.00%  ±1.34%  ±1.74%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=128 encoding='ascii'                           0.12 %       ±5.16%  ±6.86%  ±8.93%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=128 encoding='base64-ascii'                    1.06 %       ±7.14%  ±9.49% ±12.36%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=128 encoding='base64-utf8'                    -0.82 %       ±5.62%  ±7.47%  ±9.73%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=128 encoding='utf16le'                        -1.15 %       ±3.55%  ±4.73%  ±6.17%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=128 encoding='utf8'                     *     -2.32 %       ±1.91%  ±2.54%  ±3.30%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=32 encoding='ascii'                           -1.22 %       ±6.09%  ±8.10% ±10.55%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=32 encoding='base64-ascii'                     0.32 %       ±5.45%  ±7.25%  ±9.43%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=32 encoding='base64-utf8'                      4.24 %       ±5.86%  ±7.82% ±10.20%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=32 encoding='utf16le'                         -2.18 %       ±6.94%  ±9.24% ±12.04%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=32 encoding='utf8'                            -0.14 %       ±3.38%  ±4.50%  ±5.86%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='ascii'                          0.80 %       ±1.43%  ±1.92%  ±2.53%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='base64-ascii'                  -0.28 %       ±4.81%  ±6.40%  ±8.34%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='base64-utf8'                    3.36 %       ±4.54%  ±6.04%  ±7.88%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='utf16le'                        0.50 %       ±0.79%  ±1.05%  ±1.37%
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='utf8'                  ***     -1.62 %       ±0.91%  ±1.21%  ±1.59%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 88 comparisons, you can thus
expect the following amount of false-positive results:
  4.40 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.88 false positives, when considering a   1% risk acceptance (**, ***),
  0.09 false positives, when considering a 0.1% risk acceptance (***)

No significant perf regression.

@RaisinTen RaisinTen changed the title string_decoder: fix crash when calling __proto__.write() string_decoder: fix crash when calling __proto__.write() using C++ Feb 20, 2022
@nodejs-github-bot
Copy link
Collaborator

@RaisinTen
Copy link
Contributor Author

Superseded by #42062 because:

  • there were no significant perf regressions in either of the two
  • JS is the more approachable language
  • we do such validations in JS mostly

@RaisinTen RaisinTen closed this Mar 5, 2022
@RaisinTen RaisinTen deleted the string_decoder/fix-crash-when-calling-__proto__.write-c++ branch March 9, 2022 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

message: "Assertion `val->IsArrayBufferView()' failed."
3 participants