{"record":{"id":"0b2a6b72d7726cb1","repo":"mozilla/pdf.js","slug":"invalid-rotation-0b2a6b","errorCode":null,"errorMessage":"Invalid rotation","messagePattern":"Invalid rotation","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/editor/editor.js","lineNumber":1645,"sourceCode":"          x + shiftY + height + pageX,\n          pageHeight - y + shiftX + width + pageY,\n        ];\n      case 180:\n        return [\n          x - shiftX - width + pageX,\n          pageHeight - y + shiftY + pageY,\n          x - shiftX + pageX,\n          pageHeight - y + shiftY + height + pageY,\n        ];\n      case 270:\n        return [\n          x - shiftY - height + pageX,\n          pageHeight - y - shiftX - width + pageY,\n          x - shiftY + pageX,\n          pageHeight - y - shiftX + pageY,\n        ];\n      default:\n        throw new Error(\"Invalid rotation\");\n    }\n  }\n\n  getRectInCurrentCoords(rect, pageHeight) {\n    const [x1, y1, x2, y2] = rect;\n\n    const width = x2 - x1;\n    const height = y2 - y1;\n\n    switch (this.rotation) {\n      case 0:\n        return [x1, pageHeight - y2, width, height];\n      case 90:\n        return [x1, pageHeight - y1, height, width];\n      case 180:\n        return [x2, pageHeight - y1, width, height];\n      case 270:\n        return [x2, pageHeight - y2, height, width];","sourceCodeStart":1627,"sourceCodeEnd":1663,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/editor/editor.js#L1627-L1663","documentation":"Thrown by AnnotationEditor.getRect's switch statement in its default branch. getRect computes page-space corners for the editor based on this.rotation, which is expected to be one of 0, 90, 180, or 270. Any other value means the editor's rotation field is uninitialized, corrupted, or set to a non-normalized angle (e.g., 45, 360, negative).","triggerScenarios":"An editor instance loaded from serialized data whose rotation field is not one of the four canonical values; setting editor.rotation = 45 directly; deserialization from a tampered or malformed annotation.","commonSituations":"Loading an annotation export with a non-standard rotation; bugs in upstream code that assign arbitrary angles; round-tripping through tools that do not normalize rotation.","solutions":["Normalize rotation to the nearest quadrant before instantiating the editor: r => ((r % 360) + 360) % 360 then snap to {0,90,180,270}.","Validate the rotation field when deserializing and reject/repair unexpected values.","Never set editor.rotation to non-orthogonal values."],"exampleFix":"// before\neditor.rotation = rawRotation;\n\n// after\nfunction normalize(r) {\n  r = ((r % 360) + 360) % 360;\n  return [0, 90, 180, 270].reduce((best, v) =>\n    Math.abs(v - r) < Math.abs(best - r) ? v : best, 0);\n}\neditor.rotation = normalize(rawRotation);","handlingStrategy":"validation","validationCode":"function normalizeRotation(r) {\n  r = ((Number(r) || 0) % 360 + 360) % 360;\n  return [0, 90, 180, 270].reduce((best, v) =>\n    Math.abs(v - r) < Math.abs(best - r) ? v : best, 0);\n}\neditor.rotation = normalizeRotation(rawRotation);","typeGuard":"const isCanonicalRotation = (r): r is 0 | 90 | 180 | 270 =>\n  r === 0 || r === 90 || r === 180 || r === 270;","tryCatchPattern":"null","preventionTips":["Always snap rotation to {0,90,180,270} at the boundary.","Sanitize serialized editor state on load.","Reject non-orthogonal angles from imports."],"tags":["editor","annotations","rotation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}