-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: reject loadImage when src is null or invalid #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ian-I-Chien
wants to merge
1
commit into
Automattic:master
Choose a base branch
from
Ian-I-Chien:reject-null-for-loadImage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: reject loadImage when src is null or invalid #2518
Ian-I-Chien
wants to merge
1
commit into
Automattic:master
from
Ian-I-Chien:reject-null-for-loadImage
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm also encountering this issue. I hope it can be merged. |
Description: - Prevents loadImage() from getting stuck when given null or undefined - Add test cases for '', null, and undefined inputs to loadImage() Test Result: ``` npm test > [email protected] test > mocha test/*.test.js Canvas ✓ Prototype and ctor are well-shaped, don't hit asserts on accessors (AutomatticGH-803) ✓ registerFont ✓ color serialization ✓ color parser ✓ Canvas#type ✓ Canvas#getContext("2d") ✓ Canvas#getContext("2d", {pixelFormat: string}) ✓ Canvas#getContext("2d", {alpha: boolean}) ✓ Canvas#{width,height}= ✓ Canvas#width= (resurfacing) doesn't crash when fillStyle is a pattern (Automattic#1357) ✓ SVG Canvas#width changes don't crash (Automattic#1380) ✓ Canvas#stride ✓ Canvas#getContext("invalid") ✓ Context2d#patternQuality ✓ Context2d#imageSmoothingEnabled ✓ Context2d#font= ✓ Context2d#lineWidth= ✓ Context2d#antiAlias= ✓ Context2d#lineCap= ✓ Context2d#lineJoin= ✓ Context2d#globalAlpha= ✓ Context2d#isPointInPath() ✓ Context2d#textAlign ✓ Context2d#fillText() ✓ Context2d#currentTransform ✓ Context2d#createImageData(ImageData) ✓ Context2d#createPattern(Canvas) ✓ Context2d#createPattern(Canvas).setTransform() ✓ Context2d#createPattern(Image) ✓ CanvasPattern stringifies as [object CanvasPattern] ✓ CanvasPattern has class string of `CanvasPattern` ✓ Context2d#createLinearGradient() ✓ Canvas has class string of `HTMLCanvasElement` ✓ CanvasGradient stringifies as [object CanvasGradient] ✓ CanvasGradient has class string of `CanvasGradient` ✓ Canvas#createPNGStream() ✓ Canvas#createPDFStream() ✓ Canvas#createJPEGStream() ✓ EOI at end of Canvas#createJPEGStream() ✓ Context2d#fill() ✓ Context2d#clip() ✓ Context2d#IsPointInPath() ✓ Context2d#rotate(angle) ✓ Context2d#drawImage() ✓ Context2d#SetFillColor() #toBuffer ✓ Canvas#toBuffer() ✓ Canvas#toBuffer("image/png") ✓ Canvas#toBuffer("image/png", {resolution: 96}) ✓ Canvas#toBuffer("image/png", {compressionLevel: 5}) ✓ Canvas#toBuffer("image/png", {filters: PNG_ALL_FILTERS}) ✓ Canvas#toBuffer("image/jpeg") ✓ Canvas#toBuffer("image/jpeg", {quality: 0.95}) ✓ Canvas#toBuffer(callback) ✓ Canvas#toBuffer(callback, "image/jpeg") ✓ Canvas#toBuffer(callback, "image/jpeg", {quality: 0.95}) ✓ Canvas#toBuffer("application/pdf") #toBuffer("raw") ✓ should have the correct size ✓ does not premultiply alpha ✓ draws red ✓ draws green ✓ draws black ✓ leaves undrawn pixels black, transparent ✓ is immutable #toDataURL() ✓ toDataURL() works and defaults to PNG ✓ toDataURL(0.5) works and defaults to PNG ✓ toDataURL(undefined) works and defaults to PNG ✓ toDataURL("image/png") works ✓ toDataURL("image/png", 0.5) works ✓ toDataURL("iMaGe/PNg") works ✓ toDataURL("image/jpeg") works ✓ toDataURL(function (err, str) {...}) works and defaults to PNG ✓ toDataURL(function (err, str) {...}) is async even with no canvas data ✓ toDataURL(0.5, function (err, str) {...}) works and defaults to PNG ✓ toDataURL(undefined, function (err, str) {...}) works and defaults to PNG ✓ toDataURL("image/png", function (err, str) {...}) works ✓ toDataURL("image/png", 0.5, function (err, str) {...}) works ✓ toDataURL("image/png", {}) works ✓ toDataURL("image/jpeg", {}) works ✓ toDataURL("image/jpeg", function (err, str) {...}) works ✓ toDataURL("iMAge/JPEG", function (err, str) {...}) works ✓ toDataURL("image/jpeg", undefined, function (err, str) {...}) works ✓ toDataURL("image/jpeg", 0.5, function (err, str) {...}) works ✓ toDataURL("image/jpeg", opts, function (err, str) {...}) works Context2d#createImageData(width, height) ✓ works ✓ works, A8 format ✓ works, A1 format ✓ works, RGB24 format ✓ works, RGB16_565 format Context2d#measureText() ✓ Context2d#measureText().width ✓ works ✓ actualBoundingBox is correct for left, center and right alignment (Automattic#1909) ✓ resolves text alignment wrt Context2d#direction Automattic#2508 Context2d#getImageData() ✓ works, full width, RGBA32 ✓ works, full width, RGB24 ✓ works, full width, RGB16_565 ✓ works, full width, A8 - works, full width, A1 - works, full width, RGB30 ✓ works, slice, RGBA32 ✓ works, slice, RGB24 ✓ works, slice, RGB16_565 ✓ works, slice, A8 - works, slice, A1 - works, slice, RGB30 ✓ works, assignment ✓ throws if indexes are invalid ✓ throws if canvas is a PDF canvas (Automattic#1853) slice partially outside the canvas left ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 right ✓ works, RGBA32 ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 left and right ✓ works, RGBA32 ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 top ✓ works, RGBA32 ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 bottom ✓ works, RGBA32 ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 top to bottom ✓ works, RGBA32 ✓ works, RGB24 ✓ works, RGB16_565 ✓ works, A8 does not throw if rectangle is outside the canvas (Automattic#2024) ✓ on the left ✓ on the right ✓ on the top ✓ on the bottom Context2d#putImageData() ✓ throws for invalid arguments ✓ throws if canvas is a PDF canvas (Automattic#1853) ✓ works for negative source values ✓ works, RGBA32 ✓ works, RGB24/alpha:false ✓ works, A8 ✓ works, RGB16_565 Context2d#save()/restore() ✓ 2d.state.saverestore.strokeStyle ✓ 2d.state.saverestore.fillStyle ✓ 2d.state.saverestore.globalAlpha ✓ 2d.state.saverestore.lineWidth ✓ 2d.state.saverestore.lineCap ✓ 2d.state.saverestore.lineJoin ✓ 2d.state.saverestore.miterLimit ✓ 2d.state.saverestore.shadowOffsetX ✓ 2d.state.saverestore.shadowOffsetY ✓ 2d.state.saverestore.shadowBlur ✓ 2d.state.saverestore.shadowColor ✓ 2d.state.saverestore.globalCompositeOperation ✓ 2d.state.saverestore.font ✓ 2d.state.saverestore.textAlign ✓ 2d.state.saverestore.textBaseline ✓ 2d.state.saverestore.imageSmoothingEnabled ✓ 2d.state.saverestore.lineDashOffset ✓ 2d.state.saverestore.patternQuality ✓ 2d.state.saverestore.textDrawingMode ✓ 2d.state.saverestore.antialias Context2d#beingTag()/endTag() ✓ generates a pdf ✓ requires tag argument ✓ requires attributes to be a string loadImage ✓ doesn't crash when you don't specify width and height DOMMatrix constructor, general ✓ aliases a,b,c,d,e,f properly ✓ parses lists of transforms per spec ✓ parses matrix2d(<16 numbers>) per spec ✓ sets is2D to true if matrix2d(<16 numbers>) is 2D multiply ✓ performs self.other, returning a new DOMMatrix multiplySelf ✓ performs self.other, mutating self preMultiplySelf ✓ performs other.self, mutating self translateSelf ✓ works, 1 arg ✓ works, 2 args ✓ works, 3 args scale ✓ works, 1 arg ✓ works, 2 args ✓ works, 3 args ✓ works, 4 args ✓ works, 5 args ✓ works, 6 args scale3d ✓ works, 0 args ✓ works, 1 arg ✓ works, 2 args ✓ works, 3 args ✓ works, 4 args rotate ✓ works, 1 arg ✓ works, 2 args ✓ works, 3 args rotateFromVector ✓ works, no args and x/y=0 ✓ works rotateAxisAngle ✓ works, 0 args ✓ works, 4 args skewX ✓ works skewY ✓ works flipX ✓ works flipY ✓ works invertSelf ✓ works for invertible matrices ✓ works for non-invertible matrices inverse ✓ preserves the original DOMMatrix ✓ preserves the original DOMMatrix for non-invertible matrices transformPoint ✓ works toFloat32Array ✓ works toFloat64Array ✓ works toString ✓ works, 2d ✓ works, 3d toJSON ✓ works, 2d ✓ works, 3d Font parser ✓ 20px Arial ✓ 20pt Arial ✓ 20.5pt Arial ✓ 20% Arial ✓ 20mm Arial ✓ 20px serif ✓ 20px sans-serif ✓ 20px monospace ✓ 50px Arial, sans-serif ✓ bold italic 50px Arial, sans-serif ✓ 50px Helvetica , Arial, sans-serif ✓ 50px "Helvetica Neue", sans-serif ✓ 50px "Helvetica Neue", "foo bar baz" , sans-serif ✓ 50px 'Helvetica Neue' ✓ italic 20px Arial ✓ oblique 20px Arial ✓ normal 20px Arial ✓ 300 20px Arial ✓ 800 20px Arial ✓ bolder 20px Arial ✓ lighter 20px Arial ✓ normal normal normal 16px Impact ✓ italic small-caps bolder 16px cursive ✓ 20px "new century schoolbook", serif ✓ 20px "Arial bold 300" ✓ 50px "Helvetica 'Neue'", "foo \"bar\" baz" , "Someone's weird \'edge\' case", sans-serif ✓ Helvetica, sans ✓ 123px thefont/123abc ✓ 123px / normal thefont ✓ 12px/1.2whoops arial ✓ bold bold 12px thefont ✓ italic italic 12px Arial ✓ small-caps bold italic small-caps 12px Arial ✓ small-caps bold oblique 12px 'A'ri\61l ✓ 12px/34% "The\ Word" ✓ ✓ normal normal normal 1%/normal a , 'b' ✓ normalnormalnormal 1px/normal a ✓ 12px _the_font ✓ 9px 7 birds ✓ 2em "Courier ✓ 2em \'Courier\" ✓ 1px \10abcde ✓ 3E+2 1e-1px yay Image ✓ Prototype and ctor are well-shaped, don't hit asserts on accessors (AutomatticGH-803) ✓ Image has class string of `HTMLImageElement` ✓ loads JPEG image ✓ loads JPEG data URL ✓ loads PNG image ✓ loads PNG data URL ✓ detects invalid PNG ✓ propagates exceptions thrown by onload ✓ propagates exceptions thrown by onerror ✓ loads SVG data URL base64 ✓ loads SVG data URL utf8 ✓ calls Image#onload multiple times ✓ handles errors ✓ returns a nice, coded error for fopen failures ✓ captures errors from libjpeg ✓ calls Image#onerror multiple times ✓ Image#{width,height} ✓ Image#src set empty buffer ✓ should unbind Image#onload ✓ should unbind Image#onerror ✓ does not crash on invalid images ✓ does not contain `source` property supports BMP ✓ parses 1-bit image ✓ parses 4-bit image - parses 8-bit image ✓ parses 24-bit image ✓ parses 32-bit image ✓ parses minimal BMP ✓ properly handles negative height ✓ color palette ✓ V3 header - V5 header ✓ catches BMP errors ✓ BMP bomb ✓ rejects when loadImage is called with null ✓ rejects when loadImage is called with undefined ✓ rejects when loadImage is called with empty string ImageData ✓ Prototype and ctor are well-shaped, don't hit asserts on accessors (AutomatticGH-803) ✓ stringifies as [object ImageData] ✓ gives class string as `ImageData` ✓ should throw with invalid numeric arguments ✓ should construct with width and height ✓ should throw with invalid typed array ✓ should construct with Uint8ClampedArray ✓ should construct with Uint16Array 291 passing (192ms) 6 pending ```
cf6b80f
to
ecd20bd
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Test Result:
Thanks for contributing!
Fix #2304