Skip to content

Commit cfb5501

Browse files
Renegade334aduh95
authored andcommitted
deps: V8: backport a05177279022
Original commit message: [temporal] Compute zoneinfo64.res length from ResB index table ICU4C's offsetTOCLookupFn sets UDataMemory::length = -1 for the last entry in a .dat archive (which occurs for zoneinfo64.res in small-icu builds where zu.res is excluded), and pointerTOCLookupFn sets length = -1 for all entries in pointer TOC builds. When UDataMemory::length is -1, compute the bundle byte length from the ResB header offset (udata_getMemory(memory) - data) and the self-describing URES_INDEX_BUNDLE_TOP word in the ResB index table, matching ICU4C's res_init() in uresdata.cpp. Also check USING_SYSTEM_ICU in addition to V8_ENABLE_TEMPORAL_SYSTEMICU when deciding whether internal udatamem.h is available. Bug: 576986967 Change-Id: I7a2c881eb3891a97eafb244f71aa405ff2434b51 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8642579 Commit-Queue: Manish Goregaokar <manishearth@google.com> Reviewed-by: Rezvan Mahdavi Hezaveh <rezvan@chromium.org> Cr-Commit-Position: refs/heads/main@{#111181} Refs: v8/v8@a051772 Co-authored-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #67416 Refs: https://issues.chromium.org/issues/576986967 Refs: #62676 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Steven R Loomis <srl295@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 098b478 commit cfb5501

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎common.gypi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
# Reset this number to 0 on major V8 upgrades.
5252
# Increment by one for each non-official patch applied to deps/v8.
53-
'v8_embedder_string': '-node.13',
53+
'v8_embedder_string': '-node.14',
5454

5555
##### V8 defaults for Node.js #####
5656

‎deps/v8/src/objects/js-temporal-zoneinfo64.cc‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "temporal_rs/TimeZone.hpp"
1212

1313
#ifdef V8_INTL_SUPPORT
14-
#ifndef V8_ENABLE_TEMPORAL_SYSTEMICU
14+
#if !defined(V8_ENABLE_TEMPORAL_SYSTEMICU) && !defined(USING_SYSTEM_ICU)
1515
// ICU internal header file
1616
#include "udatamem.h"
1717
#else
@@ -58,7 +58,7 @@ ZoneInfo64Provider::ZoneInfo64Provider() {
5858
provider = temporal_rs::Provider::empty();
5959
return;
6060
}
61-
#ifndef V8_ENABLE_TEMPORAL_SYSTEMICU
61+
#if !defined(V8_ENABLE_TEMPORAL_SYSTEMICU) && !defined(USING_SYSTEM_ICU)
6262
// NOT udata_getLength: this ignores the header,
6363
// and we're parsing resb files with the header
6464
auto length = memory->length;
@@ -71,6 +71,51 @@ ZoneInfo64Provider::ZoneInfo64Provider() {
7171
auto length = shadowMemory->length;
7272
auto data = shadowMemory->data;
7373
#endif
74+
DCHECK_WITH_MSG(data != nullptr, "ICU4C returned nullptr");
75+
if (data == nullptr) {
76+
provider = temporal_rs::Provider::empty();
77+
return;
78+
}
79+
// ICU4C sets length = -1 for the last entry in an offset TOC (.dat) archive
80+
// (e.g. when zoneinfo64.res is the final entry in a small-icu build) and for
81+
// all entries in a pointer TOC archive. Determine the exact byte length of
82+
// the ResB bundle from its self-describing index table (see res_init() in
83+
// ICU4C's uresdata.cpp).
84+
int32_t resb_length = -1;
85+
const void* body = udata_getMemory(memory);
86+
if (body != nullptr) {
87+
ptrdiff_t header_length =
88+
static_cast<const uint8_t*>(body) - static_cast<const uint8_t*>(data);
89+
constexpr uint32_t kUresIndexBundleTop = 3;
90+
constexpr ptrdiff_t kMinResbBytes = static_cast<ptrdiff_t>(
91+
(1 + 1 + kUresIndexBundleTop) * sizeof(uint32_t));
92+
if (header_length >= 0 && header_length % 4 == 0 &&
93+
(length == -1 || length >= header_length + kMinResbBytes)) {
94+
const uint32_t* body_32 = static_cast<const uint32_t*>(body);
95+
// body_32[0] is the root resource word; body_32[1..] is indexes[].
96+
// indexes[URES_INDEX_LENGTH] & 0xff holds the length of indexes[].
97+
uint32_t index_length = body_32[1] & 0xff;
98+
if (index_length > kUresIndexBundleTop) {
99+
// indexes[URES_INDEX_BUNDLE_TOP] is the number of 32-bit words in the
100+
// bundle body.
101+
uint32_t bundle_top = body_32[1 + kUresIndexBundleTop];
102+
if (bundle_top >= 1 + index_length && bundle_top <= 0x1000000) {
103+
resb_length = static_cast<int32_t>(header_length) +
104+
static_cast<int32_t>(bundle_top * sizeof(uint32_t));
105+
}
106+
}
107+
}
108+
}
109+
DCHECK_WITH_MSG(resb_length != -1,
110+
"zoneinfo64.res should have a valid ResB index table");
111+
DCHECK_IMPLIES(length != -1, resb_length <= length);
112+
if (resb_length == -1 || (length != -1 && resb_length > length)) {
113+
provider = temporal_rs::Provider::empty();
114+
return;
115+
}
116+
if (length == -1) {
117+
length = resb_length;
118+
}
74119
// This really shouldn't happen: ICU4C pads these files
75120
// to 4 when baking them in
76121
DCHECK_WITH_MSG(length % 4 == 0, "ICU4C should pad udata to uint32_t");
@@ -80,7 +125,6 @@ ZoneInfo64Provider::ZoneInfo64Provider() {
80125
provider = temporal_rs::Provider::empty();
81126
return;
82127
}
83-
DCHECK_WITH_MSG(data != nullptr, "ICU4C returned nullptr");
84128

85129
const uint32_t* data_32 = static_cast<const uint32_t*>(data);
86130
std::span<const uint32_t> data_span(data_32, length / 4);

0 commit comments

Comments
 (0)