Skip to content

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

Closed
RaisinTen wants to merge 1 commit into
nodejs:masterfrom
RaisinTen:string_decoder/fix-crash-when-calling-__proto__.write-c++
Closed

RaisinTen wants to merge 1 commit into
nodejs:masterfrom
RaisinTen:string_decoder/fix-crash-when-calling-__proto__.write-c++

Conversation

@RaisinTen

Copy link
Copy Markdown
Member

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

RaisinTen commented Feb 20, 2022 •

Copy link
Copy Markdown
Member Author

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

Details
                                                                                            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
Copy Markdown
Collaborator

@RaisinTen

Copy link
Copy Markdown
Member 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