deps: update nbytes to 0.1.5

PR-URL: https://github.com/nodejs/node/pull/67688
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
Node.js GitHub Bot authored and Antoine du Hamel committed 2026-11-25 18:00:58 +01:00
1 parent 03b8203e92
commit 3ea9c25bcb
5 files changed
+70 -16

No files matched your search

+1 -1
View File
@@ -1,3 +1,3 @@
{
".": "0.1.4"
".": "0.1.5"
}
+7
View File
@@ -1,5 +1,12 @@
# Changelog
## [0.1.5](https://github.com/nodejs/nbytes/compare/v0.1.4...v0.1.5) (2026-11-16)
### Bug Fixes
* **base64, hex:** enhance decoding to ignore non-Latin1 characters ([#17](https://github.com/nodejs/nbytes/issues/17)) ([c0328e6](https://github.com/nodejs/nbytes/commit/c0328e6cc55b1aaae982d626c2f5a01f51cd2134))
## [0.1.4](https://github.com/nodejs/nbytes/compare/v0.1.3...v0.1.4) (2026-04-09)
+1 -1
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.28)
project(nbytes VERSION 0.1.4) # x-release-please-version
project(nbytes VERSION 0.1.5) # x-release-please-version
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
+28 -14
View File
@@ -109,6 +109,15 @@ bool SwapBytes64(char *data, size_t nbytes);
extern const int8_t unbase64_table[256];
// Code units above 0xFF are never base64 digits; do not truncate them.
template <typename TypeName>
inline int8_t Unbase64(TypeName c) {
if constexpr (sizeof(TypeName) > 1) {
if (c > 0xFF) return -1;
}
return unbase64_table[static_cast<uint8_t>(c)];
}
template <typename TypeName>
bool Base64DecodeGroupSlow(char *const dst, const size_t dstlen,
const TypeName *const src, const size_t srclen,
@@ -117,8 +126,8 @@ bool Base64DecodeGroupSlow(char *const dst, const size_t dstlen,
uint8_t lo;
#define V(expr) \
for (;;) { \
const uint8_t c = static_cast<uint8_t>(src[*i]); \
lo = unbase64_table[c]; \
const TypeName c = src[*i]; \
lo = Unbase64(c); \
*i += 1; \
if (lo < 64) break; /* Legal character. */ \
if (c == '=' || *i >= srclen) return false; /* Stop decoding. */ \
@@ -179,14 +188,10 @@ size_t Base64DecodeFast(char *const dst, const size_t dstlen,
size_t k = 0;
while (i < max_i && k < max_k) {
const unsigned char txt[] = {
static_cast<unsigned char>(
unbase64_table[static_cast<uint8_t>(src[i + 0])]),
static_cast<unsigned char>(
unbase64_table[static_cast<uint8_t>(src[i + 1])]),
static_cast<unsigned char>(
unbase64_table[static_cast<uint8_t>(src[i + 2])]),
static_cast<unsigned char>(
unbase64_table[static_cast<uint8_t>(src[i + 3])]),
static_cast<unsigned char>(Unbase64(src[i + 0])),
static_cast<unsigned char>(Unbase64(src[i + 1])),
static_cast<unsigned char>(Unbase64(src[i + 2])),
static_cast<unsigned char>(Unbase64(src[i + 3])),
};
const uint32_t v = ReadUint32BE(txt);
@@ -224,13 +229,22 @@ size_t Base64Decode(char *const dst, const size_t dstlen,
extern const int8_t unhex_table[256];
// Code units above 0xFF are never hex digits; do not truncate them.
template <typename TypeName>
inline int8_t Unhex(TypeName c) {
if constexpr (sizeof(TypeName) > 1) {
if (c > 0xFF) return -1;
}
return unhex_table[static_cast<uint8_t>(c)];
}
template <typename TypeName>
static size_t HexDecode(char *buf, size_t len, const TypeName *src,
const size_t srcLen) {
size_t i;
for (i = 0; i < len && i * 2 + 1 < srcLen; ++i) {
unsigned a = unhex_table[static_cast<uint8_t>(src[i * 2 + 0])];
unsigned b = unhex_table[static_cast<uint8_t>(src[i * 2 + 1])];
unsigned a = Unhex(src[i * 2 + 0]);
unsigned b = Unhex(src[i * 2 + 1]);
if (!~a || !~b) return i;
buf[i] = (a << 4) | b;
}
@@ -836,12 +850,12 @@ size_t SearchString(const char *haystack, size_t haystack_length,
// ============================================================================
// Version metadata
#define NBYTES_VERSION "0.1.4" // x-release-please-version
#define NBYTES_VERSION "0.1.5" // x-release-please-version
enum {
NBYTES_VERSION_MAJOR = 0, // x-release-please-major
NBYTES_VERSION_MINOR = 1, // x-release-please-minor
NBYTES_VERSION_REVISION = 4, // x-release-please-patch
NBYTES_VERSION_REVISION = 5, // x-release-please-patch
};
} // namespace nbytes
+33
View File
@@ -27,3 +27,36 @@ TEST(basic, swap_bytes64) {
EXPECT_EQ(input, expected);
SUCCEED();
}
TEST(base64, decode_two_byte_ignores_non_latin1) {
// U+4E2D has the low byte 0x2D ('-'); it must not decode as a base64 digit.
const char16_t input[] = u"QUJD\u4E2DREVG";
char out[16] = {};
size_t n = nbytes::Base64Decode(out, sizeof(out), input, 9);
EXPECT_EQ(std::string(out, n), "ABCDEF");
}
TEST(base64, decode_two_byte_does_not_stop_on_low_byte_padding) {
// U+013D has the low byte 0x3D ('='); it must not end the decoding.
const char16_t input[] = u"QUJD\u013DREVG";
char out[16] = {};
size_t n = nbytes::Base64Decode(out, sizeof(out), input, 9);
EXPECT_EQ(std::string(out, n), "ABCDEF");
}
TEST(base64, decode_two_byte_all_non_latin1_is_empty) {
// Four U+4E2D units form a full group in the fast path; the output must
// still be empty rather than the bytes of "----".
const char16_t input[] = u"\u4E2D\u4E2D\u4E2D\u4E2D";
char out[16] = {};
size_t n = nbytes::Base64Decode(out, sizeof(out), input, 4);
EXPECT_EQ(n, 0u);
}
TEST(hex, decode_two_byte_rejects_non_latin1) {
// U+0141 has the low byte 0x41 ('A'); it is not a hex digit.
const char16_t input[] = u"\u0141\u0141";
char out[4] = {};
size_t n = nbytes::HexDecode(out, sizeof(out), input, 2);
EXPECT_EQ(n, 0u);
}