Welcome! Log In Create A New Profile

Advanced

[njs] Fixed atob() with non-padded base64 strings.

Dmitry Volyntsev
February 22, 2024 08:40PM
details: https://hg.nginx.org/njs/rev/272af619b821
branches:
changeset: 2289:272af619b821
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Feb 22 17:38:58 2024 -0800
description:
Fixed atob() with non-padded base64 strings.

This fixes #695 issue on Github.

diffstat:

src/njs_string.c | 9 ++++++++-
src/test/njs_unit_test.c | 12 ++++++++++++
2 files changed, 20 insertions(+), 1 deletions(-)

diffs (41 lines):

diff -r 0479e5821ab2 -r 272af619b821 src/njs_string.c
--- a/src/njs_string.c Wed Feb 14 21:34:02 2024 -0800
+++ b/src/njs_string.c Thu Feb 22 17:38:58 2024 -0800
@@ -4298,7 +4298,14 @@ njs_string_atob(njs_vm_t *vm, njs_value_
}
}

- len = njs_base64_decoded_length(str.length, pad);
+ len = str.length;
+
+ if (len % 4 != 0) {
+ pad = 4 - (len % 4);
+ len += pad;
+ }
+
+ len = njs_base64_decoded_length(len, pad);

njs_chb_init(&chain, vm->mem_pool);

diff -r 0479e5821ab2 -r 272af619b821 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Feb 14 21:34:02 2024 -0800
+++ b/src/test/njs_unit_test.c Thu Feb 22 17:38:58 2024 -0800
@@ -10093,6 +10093,18 @@ static njs_unit_test_t njs_test[] =
"].every(v => c(atob(v)).toString() == '8,52,86')"),
njs_str("true")},

+ { njs_str("atob('aGVsbG8=')"),
+ njs_str("hello") },
+
+ { njs_str("atob('aGVsbG8')"),
+ njs_str("hello") },
+
+ { njs_str("atob('TQ==')"),
+ njs_str("M") },
+
+ { njs_str("atob('TQ')"),
+ njs_str("M") },
+
/* Functions. */

{ njs_str("return"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed atob() with non-padded base64 strings.

Dmitry Volyntsev 224 February 22, 2024 08:40PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 332
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready