|
12 | 12 | #include "v8-profiler.h" |
13 | 13 | #include <cmath> |
14 | 14 | #include <iostream> |
| 15 | +#include <limits> |
15 | 16 | #include <optional> |
16 | 17 | #include <sstream> |
17 | 18 | #include <fstream> |
@@ -1280,9 +1281,12 @@ bool GetWorkerThreadPriority(Isolate *isolate, Local<Context> context, |
1280 | 1281 | } |
1281 | 1282 |
|
1282 | 1283 | constexpr double kBytesPerMegabyte = 1024 * 1024; |
1283 | | -// Bounds the double-to-size_t conversion below; v8 clamps heap sizes far under |
1284 | | -// this on every device, so nothing real is excluded. |
1285 | | -constexpr double kMaxLimitMegabytes = 1024.0 * 1024.0; |
| 1284 | +// Bounds the double-to-size_t conversion below: converting a byte count that |
| 1285 | +// does not fit size_t is undefined, and size_t is 32 bits on armeabi-v7a and |
| 1286 | +// x86. The division floors, so the product always fits. v8 clamps heap sizes |
| 1287 | +// far under this on every device, so nothing real is excluded. |
| 1288 | +constexpr size_t kMaxLimitMegabytes = |
| 1289 | + std::numeric_limits<size_t>::max() / static_cast<size_t>(kBytesPerMegabyte); |
1286 | 1290 |
|
1287 | 1291 | // v8 needs the reservation to be a whole number of table segments and no larger |
1288 | 1292 | // than its compile-time maximum; whole megabytes satisfy the first on every |
@@ -1317,11 +1321,13 @@ bool ReadMegabyteLimit(Isolate *isolate, Local<Context> context, Local<Object> r |
1317 | 1321 | } |
1318 | 1322 |
|
1319 | 1323 | double parsed = value.As<Number>()->Value(); |
1320 | | - if (!std::isfinite(parsed) || parsed * kBytesPerMegabyte < 1 || parsed > kMaxLimitMegabytes) { |
| 1324 | + if (!std::isfinite(parsed) || parsed * kBytesPerMegabyte < 1 || |
| 1325 | + parsed > static_cast<double>(kMaxLimitMegabytes)) { |
1321 | 1326 | ThrowWorkerOptionRangeError(isolate, |
1322 | 1327 | "Worker option \"" + name + |
1323 | 1328 | "\" must be a finite number of megabytes worth at " |
1324 | | - "least one byte and at most 1048576."); |
| 1329 | + "least one byte and at most " + |
| 1330 | + std::to_string(kMaxLimitMegabytes) + "."); |
1325 | 1331 | } |
1326 | 1332 |
|
1327 | 1333 | megabytes = parsed; |
|
0 commit comments