From 418f555e1645a2d0fc7e0a9e86265c69c7ddbfde Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Sat, 6 Sep 2025 21:44:30 -0700 Subject: [PATCH 1/2] bug: incorrect roundRect() with large radii Fixes #2400 --- CHANGELOG.md | 1 + src/CanvasRenderingContext2d.cc | 6 +++--- test/public/tests.js | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 940894033..b16096f69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed ### Added ### Fixed +* `roundRect()` shape incorrect when radii were large relative to rectangle size (#2400) 3.2.0 ================== diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 2342a57e5..3f52c1fdd 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -3175,10 +3175,10 @@ Context2d::RoundRect(const Napi::CallbackInfo& info) { upperLeft.x *= scale; upperLeft.y *= scale; upperRight.x *= scale; - upperRight.x *= scale; - lowerLeft.y *= scale; + upperRight.y *= scale; + lowerLeft.x *= scale; lowerLeft.y *= scale; - lowerRight.y *= scale; + lowerRight.x *= scale; lowerRight.y *= scale; } } diff --git a/test/public/tests.js b/test/public/tests.js index 165d847e6..582c0ce28 100644 --- a/test/public/tests.js +++ b/test/public/tests.js @@ -132,6 +132,11 @@ tests['roundRect()'] = function (ctx) { ctx.roundRect(135, 70, 60, 60, [{ x: 30, y: 10 }, { x: 5, y: 20 }]) ctx.fillStyle = 'darkseagreen' ctx.fill() + + ctx.beginPath() + ctx.roundRect(5, 135, 8, 60, 15) + ctx.fillStyle = 'purple' + ctx.fill() } tests['lineTo()'] = function (ctx) { From 616859b50294d859d6d59929a766afe4e4f43ec9 Mon Sep 17 00:00:00 2001 From: Ian Chien Date: Sun, 7 Sep 2025 21:54:36 +0800 Subject: [PATCH 2/2] fix: reject loadImage when src is null or invalid (#2518) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: - To handle non-string/non-Buffer sources while fetching image. - Add test cases for '', null, and undefined inputs to loadImage() Test Result: ``` npm run test ... ✔ rejects when loadImage is called with null ✔ rejects when loadImage is called with undefined ✔ rejects when loadImage is called with empty string 291 passing (302ms) 6 pending ``` --- CHANGELOG.md | 1 + lib/image.js | 4 ++++ test/image.test.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b16096f69..aafa96fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Added ### Fixed * `roundRect()` shape incorrect when radii were large relative to rectangle size (#2400) +* Reject loadImage when src is null or invalid (#2304) 3.2.0 ================== diff --git a/lib/image.js b/lib/image.js index 9ffa3c794..72243439c 100644 --- a/lib/image.js +++ b/lib/image.js @@ -63,6 +63,10 @@ Object.defineProperty(Image.prototype, 'src', { } } else if (Buffer.isBuffer(val)) { setSource(this, val) + } else { + const err = new Error("Invalid image source") + if (typeof this.onerror === 'function') this.onerror(err) + else throw err } }, diff --git a/test/image.test.js b/test/image.test.js index a5d6f415c..edae78beb 100644 --- a/test/image.test.js +++ b/test/image.test.js @@ -516,6 +516,24 @@ describe('Image', function () { img.src = path.join(bmpDir, 'bomb.bmp') }) + it('rejects when loadImage is called with null', async function () { + await assert.rejects( + loadImage(null), + ) + }) + + it('rejects when loadImage is called with undefined', async function () { + await assert.rejects( + loadImage(undefined), + ) + }) + + it('rejects when loadImage is called with empty string', async function () { + await assert.rejects( + loadImage(''), + ) + }) + function testImgd (img, data) { const ctx = createCanvas(img.width, img.height).getContext('2d') ctx.drawImage(img, 0, 0)