Skip to content

Commit 823ee3b

Browse files
authored
Merge pull request #295 from danbaruka/chore/fix-image-size-audit
chore(deps): clear remaining npm audit highs (image-size)
2 parents 95b3927 + 034f773 commit 823ee3b

121 files changed

Lines changed: 13269 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ contributor-beginner/build/
132132
.yarn/build-state.yml
133133
.yarn/install-state.gz
134134
.pnp.*
135+
136+
# Keep vendored image-size build (security patch)
137+
!website/vendor/image-size/dist/
138+
!website/vendor/image-size/dist/**

‎website/package-lock.json‎

Lines changed: 5 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎website/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"dompurify": "3.4.13",
7373
"fast-uri": "4.1.3",
7474
"http-proxy-middleware": "2.0.10",
75+
"image-size": "file:vendor/image-size",
7576
"joi": "18.2.5",
7677
"js-yaml": "4.3.2",
7778
"launch-editor": "2.14.1",
@@ -102,6 +103,7 @@
102103
"dompurify": "3.4.13",
103104
"fast-uri": "4.1.3",
104105
"http-proxy-middleware": "2.0.10",
106+
"image-size": "file:vendor/image-size",
105107
"joi": "18.2.5",
106108
"js-yaml": "4.3.2",
107109
"launch-editor": "2.14.1",

‎website/vendor/image-size/LICENSE‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2013-Present Aditya Yadav, http://netroy.in
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# image-size
2+
3+
[![Build Status](https://circleci.com/gh/image-size/image-size.svg?style=shield)](https://circleci.com/gh/image-size/image-size)
4+
[![Package Version](https://img.shields.io/npm/v/image-size.svg)](https://www.npmjs.com/package/image-size)
5+
[![Downloads](https://img.shields.io/npm/dm/image-size.svg)](http://npm-stat.com/charts.html?package=image-size&author=netroy&from=&to=)
6+
7+
Fast, lightweight NodeJS package to get dimensions of any image file or buffer.
8+
9+
## Key Features
10+
- Zero dependencies
11+
- Supports all major image formats
12+
- Works with both files and buffers
13+
- Minimal memory footprint - reads only image headers
14+
- ESM and CommonJS support
15+
- TypeScript types included
16+
17+
## Supported formats
18+
19+
- BMP
20+
- CUR
21+
- DDS
22+
- GIF
23+
- HEIC (HEIF, AVCI, AVIF)
24+
- ICNS
25+
- ICO
26+
- J2C
27+
- JPEG-2000 (JP2)
28+
- JPEG
29+
- JPEG-XL
30+
- KTX (1 and 2)
31+
- PNG
32+
- PNM (PAM, PBM, PFM, PGM, PPM)
33+
- PSD
34+
- SVG
35+
- TGA
36+
- TIFF
37+
- WebP
38+
39+
## Installation
40+
41+
```shell
42+
npm install image-size
43+
# or
44+
yarn add image-size
45+
# or
46+
pnpm add image-size
47+
```
48+
49+
## Usage
50+
51+
### Passing in a Buffer/Uint8Array
52+
Best for streams, network requests, or when you already have the image data in memory.
53+
54+
```javascript
55+
import { imageSize } from 'image-size'
56+
// or
57+
const { imageSize } = require('image-size')
58+
59+
const dimensions = imageSize(buffer)
60+
console.log(dimensions.width, dimensions.height)
61+
```
62+
63+
### Reading from a file
64+
Best for local files. Returns a promise.
65+
66+
```javascript
67+
import { imageSizeFromFile } from 'image-size/fromFile'
68+
// or
69+
const { imageSizeFromFile } = require('image-size/fromFile')
70+
71+
const dimensions = await imageSizeFromFile('photos/image.jpg')
72+
console.log(dimensions.width, dimensions.height)
73+
```
74+
75+
Note: Reading from files has a default concurrency limit of **100**
76+
To change this limit, you can call the `setConcurrency` function like this:
77+
78+
```javascript
79+
import { setConcurrency } from 'image-size/fromFile'
80+
// or
81+
const { setConcurrency } = require('image-size/fromFile')
82+
setConcurrency(123456)
83+
```
84+
85+
### Reading from a file Syncronously (not recommended) ⚠️
86+
v1.x of this library had a sync API, that internally used sync file reads.
87+
88+
This isn't recommended because this blocks the node.js main thread, which reduces the performance, and prevents this library from being used concurrently.
89+
90+
However if you still need to use this package syncronously, you can read the file syncronously into a buffer, and then pass the buffer to this library.
91+
92+
```javascript
93+
import { readFileSync } from 'node:fs'
94+
import { imageSize } from 'image-size'
95+
96+
const buffer = readFileSync('photos/image.jpg')
97+
const dimensions = imageSize(buffer)
98+
console.log(dimensions.width, dimensions.height)
99+
```
100+
101+
### 3. Command Line
102+
Useful for quick checks.
103+
104+
```shell
105+
npx image-size image1.jpg image2.png
106+
```
107+
108+
### Multi-size
109+
110+
If the target file/buffer is an HEIF, an ICO, or a CUR file, the `width` and `height` will be the ones of the largest image in the set.
111+
112+
An additional `images` array is available and returns the dimensions of all the available images
113+
114+
```javascript
115+
import { imageSizeFromFile } from 'image-size/fromFile'
116+
// or
117+
const { imageSizeFromFile } = require('image-size/fromFile')
118+
119+
const { images } = await imageSizeFromFile('images/multi-size.ico')
120+
for (const dimensions of images) {
121+
console.log(dimensions.width, dimensions.height)
122+
}
123+
```
124+
125+
### Using a URL
126+
127+
```javascript
128+
import url from 'node:url'
129+
import http from 'node:http'
130+
import { imageSize } from 'image-size'
131+
132+
const imgUrl = 'http://my-amazing-website.com/image.jpeg'
133+
const options = url.parse(imgUrl)
134+
135+
http.get(options, function (response) {
136+
const chunks = []
137+
response
138+
.on('data', function (chunk) {
139+
chunks.push(chunk)
140+
})
141+
.on('end', function () {
142+
const buffer = Buffer.concat(chunks)
143+
console.log(imageSize(buffer))
144+
})
145+
})
146+
```
147+
148+
### Disabling certain image types
149+
150+
```javascript
151+
import { disableTypes } from 'image-size'
152+
// or
153+
const { disableTypes } = require('image-size')
154+
155+
disableTypes(['tiff', 'ico'])
156+
```
157+
158+
### JPEG image orientation
159+
160+
If the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a [number between 1 and 8](https://exiftool.org/TagNames/EXIF.html#:~:text=0x0112,8%20=%20Rotate%20270%20CW) representing a type of orientation.
161+
162+
```javascript
163+
import { imageSizeFromFile } from 'image-size/fromFile'
164+
// or
165+
const { imageSizeFromFile } = require('image-size/fromFile')
166+
167+
const { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg')
168+
console.log(width, height, orientation)
169+
```
170+
171+
# Limitations
172+
173+
1. **Partial File Reading**
174+
- Only reads image headers, not full files
175+
- Some corrupted images might still report dimensions
176+
177+
2. **SVG Limitations**
178+
- Only supports pixel dimensions and viewBox
179+
- Percentage values not supported
180+
181+
3. **File Access**
182+
- Reading from files has a default concurrency limit of 100
183+
- Can be adjusted using `setConcurrency()`
184+
185+
4. **Buffer Requirements**
186+
- Some formats (like TIFF) require the full header in buffer
187+
- Streaming partial buffers may not work for all formats
188+
189+
## License
190+
191+
MIT
192+
193+
## Credits
194+
195+
not a direct port, but an attempt to have something like
196+
[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.
197+
198+
## [Contributors](Contributors.md)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Vendored `image-size` (2.0.3 local)
2+
3+
Temporary security fork of [`image-size@2.0.2`](https://www.npmjs.com/package/image-size) used via npm `overrides` / Yarn `resolutions`.
4+
5+
## Why
6+
7+
Upstream advisories GHSA-5p2g-fcmc-qvqq and GHSA-w3rx-r6r6-pgpr affect `<=2.0.2` and currently have **no patched npm release**. They cause infinite-loop DoS on crafted JXL/HEIF/ICNS buffers (zero-sized boxes/entries).
8+
9+
## Local changes
10+
11+
- Package version set to `2.0.3` so audit databases treat it as outside the vulnerable range
12+
- Reject zero-sized ISO BMFF boxes in `readBox`
13+
- Throw on zero-sized `ispe` / `jxlp` boxes and ICNS entries so offsets always advance
14+
15+
## Remove when
16+
17+
Upstream publishes a release `>2.0.2` that fixes those advisories. Then delete this folder and drop the `image-size` override/resolution.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
4+
const fs = require('node:fs')
5+
const path = require('node:path')
6+
const { imageSizeFromFile } = require('../dist/fromFile.cjs')
7+
8+
const files = process.argv.slice(2)
9+
10+
if (!files.length) {
11+
console.error('Usage: image-size image1 [image2] [image3] ...')
12+
process.exit(-1)
13+
}
14+
15+
const red = ['\x1B[31m', '\x1B[39m']
16+
const grey = ['\x1B[90m', '\x1B[39m']
17+
const green = ['\x1B[32m', '\x1B[39m']
18+
19+
function colorize(text, color) {
20+
return color[0] + text + color[1]
21+
}
22+
23+
files.forEach(async (image) => {
24+
try {
25+
if (fs.existsSync(path.resolve(image))) {
26+
const greyX = colorize('x', grey)
27+
const greyImage = colorize(image, grey)
28+
const result = await imageSizeFromFile(image)
29+
const sizes = result.images || [result]
30+
sizes.forEach((size) => {
31+
const type = size.type ?? result.type;
32+
const greyType = type ? colorize(` (${type})`, grey) : ''
33+
console.info(
34+
colorize(size.width, green) +
35+
greyX +
36+
colorize(size.height, green) +
37+
' - ' +
38+
greyImage +
39+
greyType,
40+
)
41+
})
42+
} else {
43+
console.error("file doesn't exist - ", image)
44+
}
45+
} catch (e) {
46+
console.error(colorize(e.message, red), '-', image)
47+
}
48+
})

0 commit comments

Comments
 (0)