@napi-rs/canvas 0.1.99 → 0.1.100

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.
Files changed (2) hide show
  1. package/load-image.js +11 -0
  2. package/package.json +13 -13
package/load-image.js CHANGED
@@ -31,6 +31,10 @@ module.exports = async function loadImage(source, options = {}) {
31
31
  const commaIdx = source.indexOf(',')
32
32
  const encoding = source.lastIndexOf('base64', commaIdx) < 0 ? 'utf-8' : 'base64'
33
33
  const data = Buffer.from(source.slice(commaIdx + 1), encoding)
34
+ // Empty payload would silently complete on Image (HTML spec) and the loadImage
35
+ // promise would never settle; reject upfront instead.
36
+ // See https://github.com/Brooooooklyn/canvas/issues/1255
37
+ if (data.length === 0) throw new Error(`Invalid data URI: empty payload in ${source.slice(0, 64)}`)
34
38
  return createImage(data, options.alt)
35
39
  }
36
40
  // if source is a string or URL instance
@@ -118,6 +122,13 @@ function consumeStream(res) {
118
122
  }
119
123
 
120
124
  async function createImage(src, alt) {
125
+ // Empty Buffer / Uint8Array: Image follows the HTML spec (silent completion,
126
+ // no events) so the promise below would hang. Reject upfront.
127
+ // See https://github.com/Brooooooklyn/canvas/issues/1255
128
+ if ((Buffer.isBuffer(src) || src instanceof Uint8Array) && src.length === 0) {
129
+ throw new Error('loadImage: empty image data')
130
+ }
131
+
121
132
  const image = new Image()
122
133
  if (typeof alt === 'string') image.alt = alt
123
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.99",
3
+ "version": "0.1.100",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -101,7 +101,7 @@
101
101
  "lodash": "^4.17.21",
102
102
  "npm-run-all2": "^8.0.4",
103
103
  "oxlint": "^1.34.0",
104
- "oxlint-tsgolint": "^0.21.0",
104
+ "oxlint-tsgolint": "^0.22.0",
105
105
  "pinst": "^3.0.0",
106
106
  "png.js": "^0.2.1",
107
107
  "prettier": "^3.7.4",
@@ -161,16 +161,16 @@
161
161
  }
162
162
  },
163
163
  "optionalDependencies": {
164
- "@napi-rs/canvas-linux-x64-gnu": "0.1.99",
165
- "@napi-rs/canvas-darwin-x64": "0.1.99",
166
- "@napi-rs/canvas-win32-x64-msvc": "0.1.99",
167
- "@napi-rs/canvas-win32-arm64-msvc": "0.1.99",
168
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.99",
169
- "@napi-rs/canvas-linux-x64-musl": "0.1.99",
170
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.99",
171
- "@napi-rs/canvas-linux-arm64-musl": "0.1.99",
172
- "@napi-rs/canvas-darwin-arm64": "0.1.99",
173
- "@napi-rs/canvas-android-arm64": "0.1.99",
174
- "@napi-rs/canvas-linux-riscv64-gnu": "0.1.99"
164
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.100",
165
+ "@napi-rs/canvas-darwin-x64": "0.1.100",
166
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.100",
167
+ "@napi-rs/canvas-win32-arm64-msvc": "0.1.100",
168
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.100",
169
+ "@napi-rs/canvas-linux-x64-musl": "0.1.100",
170
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.100",
171
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.100",
172
+ "@napi-rs/canvas-darwin-arm64": "0.1.100",
173
+ "@napi-rs/canvas-android-arm64": "0.1.100",
174
+ "@napi-rs/canvas-linux-riscv64-gnu": "0.1.100"
175
175
  }
176
176
  }