bare-ico 1.0.1 → 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 +35 -14
- package/package.json +2 -2
- package/prebuilds/android-arm/bare-ico.bare +0 -0
- package/prebuilds/android-arm64/bare-ico.bare +0 -0
- package/prebuilds/android-ia32/bare-ico.bare +0 -0
- package/prebuilds/android-x64/bare-ico.bare +0 -0
- package/prebuilds/darwin-arm64/bare-ico.bare +0 -0
- package/prebuilds/darwin-x64/bare-ico.bare +0 -0
- package/prebuilds/ios-arm64/bare-ico.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ico.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ico.bare +0 -0
- package/prebuilds/linux-arm64/bare-ico.bare +0 -0
- package/prebuilds/linux-x64/bare-ico.bare +0 -0
- package/prebuilds/wasi-wasm32/bare-ico.wasm +0 -0
- package/prebuilds/win32-arm64/bare-ico.bare +0 -0
- package/prebuilds/win32-x64/bare-ico.bare +0 -0
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 <stdbool.h>
|
|
5
5
|
#include <stdint.h>
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
#define STBI_NO_STDIO
|
|
11
11
|
#include "stb_image.h"
|
|
12
12
|
|
|
13
|
+
#define BARE_ICO_MAX_PIXELS (1ull << 28)
|
|
14
|
+
|
|
13
15
|
// ICO file format structures
|
|
14
16
|
typedef struct __attribute__((packed)) {
|
|
15
17
|
uint16_t reserved; // Must be 0
|
|
@@ -33,6 +35,15 @@ bare_ico__on_finalize(js_env_t *env, void *data, void *finalize_hint) {
|
|
|
33
35
|
free(data);
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
static void
|
|
39
|
+
bare_ico__free(uint8_t *data, bool from_stbi) {
|
|
40
|
+
if (from_stbi) {
|
|
41
|
+
stbi_image_free(data);
|
|
42
|
+
} else {
|
|
43
|
+
free(data);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
/**
|
|
37
48
|
* Decode ICO file to RGBA format
|
|
38
49
|
* Extracts largest image or closest to requested size
|
|
@@ -147,12 +158,15 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
147
158
|
|
|
148
159
|
int width, height, channels;
|
|
149
160
|
uint8_t *rgba_data = NULL;
|
|
161
|
+
bool from_stbi = false;
|
|
150
162
|
|
|
151
163
|
if (is_png) {
|
|
152
164
|
// PNG format - can decode directly
|
|
153
165
|
rgba_data = stbi_load_from_memory(
|
|
154
166
|
img_data, size, &width, &height, &channels, 4
|
|
155
167
|
);
|
|
168
|
+
|
|
169
|
+
from_stbi = true;
|
|
156
170
|
} else {
|
|
157
171
|
// BMP-in-ICO format: has DIB header but no BITMAPFILEHEADER
|
|
158
172
|
// Height is doubled (includes AND mask)
|
|
@@ -205,7 +219,14 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
205
219
|
return NULL;
|
|
206
220
|
}
|
|
207
221
|
|
|
208
|
-
|
|
222
|
+
if (rgba_size_64 > (int64_t) BARE_ICO_MAX_PIXELS * 4) {
|
|
223
|
+
err = js_throw_error(env, NULL, "BMP-in-ICO dimensions exceed maximum");
|
|
224
|
+
assert(err == 0);
|
|
225
|
+
|
|
226
|
+
return NULL;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
size_t row_size = (size_t) row_size_64;
|
|
209
230
|
|
|
210
231
|
// Allocate output RGBA buffer
|
|
211
232
|
width = bmp_width;
|
|
@@ -225,8 +246,8 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
225
246
|
if (bmp_bpp == 32 && bmp_compression == 0) {
|
|
226
247
|
// 32-bit RGBA - direct copy with BGR→RGB conversion
|
|
227
248
|
for (int y = 0; y < actual_height; y++) {
|
|
228
|
-
uint8_t *src = pixel_start + ((actual_height - 1 - y) * row_size
|
|
229
|
-
uint8_t *dst = rgba_data + (y * width * 4
|
|
249
|
+
uint8_t *src = pixel_start + (size_t) (actual_height - 1 - y) * row_size;
|
|
250
|
+
uint8_t *dst = rgba_data + (size_t) y * width * 4;
|
|
230
251
|
for (int x = 0; x < width; x++) {
|
|
231
252
|
dst[x * 4 + 0] = src[x * 4 + 2]; // R
|
|
232
253
|
dst[x * 4 + 1] = src[x * 4 + 1]; // G
|
|
@@ -237,8 +258,8 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
237
258
|
} else if (bmp_bpp == 24 && bmp_compression == 0) {
|
|
238
259
|
// 24-bit RGB - convert to RGBA
|
|
239
260
|
for (int y = 0; y < actual_height; y++) {
|
|
240
|
-
uint8_t *src = pixel_start + ((actual_height - 1 - y) * row_size
|
|
241
|
-
uint8_t *dst = rgba_data + (y * width * 4
|
|
261
|
+
uint8_t *src = pixel_start + (size_t) (actual_height - 1 - y) * row_size;
|
|
262
|
+
uint8_t *dst = rgba_data + (size_t) y * width * 4;
|
|
242
263
|
for (int x = 0; x < width; x++) {
|
|
243
264
|
dst[x * 4 + 0] = src[x * 3 + 2]; // R
|
|
244
265
|
dst[x * 4 + 1] = src[x * 3 + 1]; // G
|
|
@@ -250,8 +271,8 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
250
271
|
// 8-bit indexed color - use palette
|
|
251
272
|
uint8_t *palette = img_data + header_size;
|
|
252
273
|
for (int y = 0; y < actual_height; y++) {
|
|
253
|
-
uint8_t *src = pixel_start + ((actual_height - 1 - y) * row_size
|
|
254
|
-
uint8_t *dst = rgba_data + (y * width * 4
|
|
274
|
+
uint8_t *src = pixel_start + (size_t) (actual_height - 1 - y) * row_size;
|
|
275
|
+
uint8_t *dst = rgba_data + (size_t) y * width * 4;
|
|
255
276
|
for (int x = 0; x < width; x++) {
|
|
256
277
|
uint8_t index = src[x];
|
|
257
278
|
dst[x * 4 + 0] = palette[index * 4 + 2]; // R
|
|
@@ -264,8 +285,8 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
264
285
|
// 4-bit indexed color - use palette
|
|
265
286
|
uint8_t *palette = img_data + header_size;
|
|
266
287
|
for (int y = 0; y < actual_height; y++) {
|
|
267
|
-
uint8_t *src = pixel_start + ((actual_height - 1 - y) * row_size
|
|
268
|
-
uint8_t *dst = rgba_data + (y * width * 4
|
|
288
|
+
uint8_t *src = pixel_start + (size_t) (actual_height - 1 - y) * row_size;
|
|
289
|
+
uint8_t *dst = rgba_data + (size_t) y * width * 4;
|
|
269
290
|
for (int x = 0; x < width; x++) {
|
|
270
291
|
uint8_t byte = src[x / 2];
|
|
271
292
|
uint8_t index;
|
|
@@ -318,8 +339,8 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
318
339
|
|
|
319
340
|
// Set data. Use size_t arithmetic to avoid int overflow on the PNG path
|
|
320
341
|
// where width/height come from stb_image and are not pre-bounded here.
|
|
321
|
-
if (width <= 0 || height <= 0) {
|
|
322
|
-
|
|
342
|
+
if (width <= 0 || height <= 0 || (uint64_t) width * height > BARE_ICO_MAX_PIXELS) {
|
|
343
|
+
bare_ico__free(rgba_data, from_stbi);
|
|
323
344
|
err = js_throw_error(env, NULL, "Invalid decoded image dimensions");
|
|
324
345
|
assert(err == 0);
|
|
325
346
|
return NULL;
|
|
@@ -327,14 +348,14 @@ bare_ico_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
327
348
|
size_t data_len = (size_t) width * (size_t) height * 4;
|
|
328
349
|
uint8_t *result_data = malloc(data_len);
|
|
329
350
|
if (!result_data) {
|
|
330
|
-
|
|
351
|
+
bare_ico__free(rgba_data, from_stbi);
|
|
331
352
|
err = js_throw_error(env, NULL, "Memory allocation failed");
|
|
332
353
|
assert(err == 0);
|
|
333
354
|
return NULL;
|
|
334
355
|
}
|
|
335
356
|
|
|
336
357
|
memcpy(result_data, rgba_data, data_len);
|
|
337
|
-
|
|
358
|
+
bare_ico__free(rgba_data, from_stbi);
|
|
338
359
|
|
|
339
360
|
js_value_t *buffer;
|
|
340
361
|
err = js_create_external_arraybuffer(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-ico",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ICO support for Bare",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"homepage": "https://github.com/holepunchto/bare-ico#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"brittle": "^3.4.0",
|
|
35
|
-
"cmake-bare": "^1.1
|
|
35
|
+
"cmake-bare": "^1.10.1",
|
|
36
36
|
"cmake-fetch": "^1.0.0",
|
|
37
37
|
"lunte": "^1.8.0",
|
|
38
38
|
"prettier": "^3.3.3",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|