{"record":{"id":"3e270c8ff719e6d1","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform-3e270c","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.getBitForPdf","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":128,"sourceCode":"\nvar getBit = (jsPDFAPI.__acroform__.getBit = function(number, bitPosition) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.getBit\"\n    );\n  }\n  return (number & (1 << bitPosition)) === 0 ? 0 : 1;\n});\n\n/*\n * Ff starts counting the bit position at 1 and not like javascript at 0\n */\nvar getBitForPdf = (jsPDFAPI.__acroform__.getBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf\"\n    );\n  }\n  return getBit(number, bitPosition - 1);\n});\n\nvar setBitForPdf = (jsPDFAPI.__acroform__.setBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.setBitForPdf\"\n    );\n  }\n  return setBit(number, bitPosition - 1);\n});\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L110-L146","documentation":"Thrown by getBitForPdf(number, bitPosition) when either argument is NaN. PDF field flags count bit positions starting at 1 (per the PDF spec), so getBitForPdf validates inputs then delegates to getBit with bitPosition-1. Exposed at jsPDF.API.__acroform__.getBitForPdf.","triggerScenarios":"Calling getBitForPdf with NaN number or position; reading a 1-based PDF flag attribute whose underlying _F/_Ff is NaN, or whose position is derived from a missing value.","commonSituations":"Reading AcroForm boolean getters (many use getBitForPdf internally) after the flag field was corrupted; calling the helper directly with unvalidated parameters.","solutions":["Validate number and bitPosition are finite numbers (bitPosition >= 1) before calling getBitForPdf.","Keep F/Ff numeric so the 'number' argument is never NaN.","Prefer the high-level boolean properties, which manage positions, over raw helper calls."],"exampleFix":"// before\nvar printed = jsPDF.API.__acroform__.getBitForPdf(field.F, opts.pos);\n\n// after\nvar pos = Number(opts.pos);\nvar printed = isFinite(pos) && pos >= 1\n  ? jsPDF.API.__acroform__.getBitForPdf(field.F || 0, pos)\n  : 0;","handlingStrategy":"type-guard","validationCode":"function safeGetBitForPdf(number, bitPosition) {\n  number = Number(number) || 0;\n  var p = Number(bitPosition);\n  if (!isFinite(p) || p < 1) return 0;\n  return jsPDF.API.__acroform__.getBitForPdf(number, p);\n}","typeGuard":"function areFiniteNumbers(a, b) {\n  return typeof a === 'number' && isFinite(a) &&\n         typeof b === 'number' && isFinite(b) && b >= 1;\n}","tryCatchPattern":"try {\n  return jsPDF.API.__acroform__.getBitForPdf(val, pos);\n} catch (e) {\n  if (/__acroform__.getBitForPdf/.test(e.message)) return 0;\n  throw e;\n}","preventionTips":["Pass 1-based PDF positions only (>= 1).","Keep F/Ff numeric so the number argument is never NaN.","Prefer boolean property getters over direct getBitForPdf calls."],"tags":["acroform","validation","bit-ops","internal"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}