bare-image-resample 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.c CHANGED
@@ -1,5 +1,5 @@
1
1
  #include <assert.h>
2
- #include <bare.h>
2
+ #include <bare/module.h>
3
3
  #include <js.h>
4
4
  #include <stdint.h>
5
5
 
@@ -13,6 +13,10 @@
13
13
  // for, and it is how both the source and the target buffers are laid out.
14
14
  static const int64_t BYTES_PER_PIXEL = 4;
15
15
 
16
+ // Cap the resampled pixel count to keep the requested dimensions from reaching
17
+ // the allocator. 256 Mpx at 4 bytes per pixel covers up to a 16384x16384 image.
18
+ #define BARE_IMAGE_RESAMPLE_MAX_PIXELS (1ull << 28)
19
+
16
20
  static js_value_t *
17
21
  bare_image_resample_resize(js_env_t *env, js_callback_info_t *info) {
18
22
  int err;
@@ -73,6 +77,16 @@ bare_image_resample_resize(js_env_t *env, js_callback_info_t *info) {
73
77
  return NULL;
74
78
  }
75
79
 
80
+ if (
81
+ (uint64_t) source_width * (uint64_t) source_height > BARE_IMAGE_RESAMPLE_MAX_PIXELS ||
82
+ (uint64_t) target_width * (uint64_t) target_height > BARE_IMAGE_RESAMPLE_MAX_PIXELS
83
+ ) {
84
+ err = js_throw_error(env, NULL, "Image dimensions exceed maximum");
85
+ assert(err == 0);
86
+
87
+ return NULL;
88
+ }
89
+
76
90
  uint64_t target_len = (uint64_t) target_width * (uint64_t) target_height * BYTES_PER_PIXEL;
77
91
 
78
92
  if (target_len > SIZE_MAX) {
@@ -86,7 +100,8 @@ bare_image_resample_resize(js_env_t *env, js_callback_info_t *info) {
86
100
 
87
101
  uint8_t *target;
88
102
  err = js_create_unsafe_arraybuffer(env, (size_t) target_len, (void **) &target, &result);
89
- assert(err == 0);
103
+
104
+ if (err < 0) return NULL;
90
105
 
91
106
  stbir_resize(
92
107
  source,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-image-resample",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Image resampling support for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "bare-jpeg": "^1.0.2",
34
34
  "brittle": "^3.4.0",
35
- "cmake-bare": "^1.1.2",
35
+ "cmake-bare": "^1.10.1",
36
36
  "cmake-fetch": "^1.4.6",
37
37
  "lunte": "^1.8.0",
38
38
  "prettier": "^3.3.3",