{"record":{"id":"8134bf988ab49616","repo":"mozilla/pdf.js","slug":"invalid-svg-dimensions","errorCode":null,"errorMessage":"Invalid SVG dimensions","messagePattern":"Invalid SVG dimensions","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/svg_factory.js","lineNumber":30,"sourceCode":" * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SVG_NS, unreachable } from \"../shared/util.js\";\n\nclass BaseSVGFactory {\n  constructor() {\n    if (\n      (typeof PDFJSDev === \"undefined\" || PDFJSDev.test(\"TESTING\")) &&\n      this.constructor === BaseSVGFactory\n    ) {\n      unreachable(\"Cannot initialize BaseSVGFactory.\");\n    }\n  }\n\n  create(width, height, skipDimensions = false) {\n    if (width <= 0 || height <= 0) {\n      throw new Error(\"Invalid SVG dimensions\");\n    }\n    const svg = this._createSVG(\"svg:svg\");\n    svg.setAttribute(\"version\", \"1.1\");\n\n    if (!skipDimensions) {\n      svg.setAttribute(\"width\", `${width}px`);\n      svg.setAttribute(\"height\", `${height}px`);\n    }\n\n    svg.setAttribute(\"preserveAspectRatio\", \"none\");\n    svg.setAttribute(\"viewBox\", `0 0 ${width} ${height}`);\n\n    return svg;\n  }\n\n  createElement(type) {\n    if (typeof type !== \"string\") {\n      throw new Error(\"Invalid SVG element type\");","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/svg_factory.js#L12-L48","documentation":"Thrown by BaseSVGFactory.create when width or height is less than or equal to zero. The factory builds an SVG with a viewBox and explicit pixel dimensions, which require strictly positive sizes. A non-positive size is treated as invalid caller input rather than an empty graphic.","triggerScenarios":"factory.create(width, height) is called with width<=0 or height<=0.","commonSituations":"Dimensions computed from a zero-area page crop, an empty text/annotation bbox, or a fallback when a size could not be determined; passing undefined which coerces via comparison.","solutions":["Validate width and height are positive numbers before calling create().","Guard upstream: skip SVG generation for zero-area content instead of forcing it.","Default to a small positive size only if a non-empty graphic is genuinely required.","Trace where the dimension originates to fix the root cause."],"exampleFix":"// before\nconst svg = factory.create(crop.width, crop.height);\n// after\nif (crop.width > 0 && crop.height > 0) {\n  const svg = factory.create(crop.width, crop.height);\n}","handlingStrategy":"validation","validationCode":"if (!(Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0)) {\n  throw new Error('width and height must be positive finite numbers');\n}","typeGuard":"function areValidSvgDimensions(width, height) {\n  return Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0;\n}","tryCatchPattern":null,"preventionTips":["Skip SVG creation for zero-area content rather than forcing it.","Trace dimension sources (crops, bboxes) to their origin when they go zero/negative.","Always validate positive finite numbers before calling create().","Avoid passing undefined, which silently fails the > 0 check."],"tags":["svg","factory","input-validation","dimensions"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}