{"id":"ba9d3a35736c22fa","repo":"webpack/webpack","slug":"section-table-does-not-match-file-size","errorCode":null,"errorMessage":"Section table does not match file size","messagePattern":"Section table does not match file size","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/serialization/FileMiddleware.js","lineNumber":873,"sourceCode":"\t}\n\t/** @type {string[]} */\n\tconst names = [];\n\tfor (let i = 0; i < sectionCount; i++) {\n\t\tconst length = buf.readInt32LE(8 + i * 4);\n\t\tif (length < 0) {\n\t\t\t// pointer section: u64 size + utf-8 file name\n\t\t\tconst end = offset - length;\n\t\t\tif (end > buf.length) {\n\t\t\t\tthrow new Error(\"Truncated pointer section\");\n\t\t\t}\n\t\t\tnames.push(buf.toString(\"utf8\", offset + 8, end));\n\t\t\toffset = end;\n\t\t} else {\n\t\t\toffset += length;\n\t\t}\n\t}\n\tif (offset !== buf.length) {\n\t\tthrow new Error(\"Section table does not match file size\");\n\t}\n\treturn names;\n};\n\n/**\n * Reads the pointer names of a compressed file by decompressing it fully\n * (compressed content cannot be read by byte range).\n * @param {IntermediateFileSystem} fs a file system\n * @param {string} file absolute path of the serialized file\n * @returns {Promise<string[]>} referenced file names (without extension)\n */\nconst getReferencedFilenamesCompressed = (fs, file) =>\n\tnew Promise((resolve, reject) => {\n\t\tfs.readFile(file, (err, rawContent) => {\n\t\t\tif (err) return reject(err);\n\t\t\t/**\n\t\t\t * Parses the decompressed content.\n\t\t\t * @param {Error | null} err error","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/serialization/FileMiddleware.js#L855-L891","documentation":"After walking every section, parsePointerNames asserts the running offset equals the buffer length exactly; any mismatch throws `Section table does not match file size` (lib/serialization/FileMiddleware.js:872-874). The walk either overshot (table over-counted) or undershot (trailing bytes the table does not account for).","triggerScenarios":"Section sizes in the header sum to a length that disagrees with the actual file length — e.g. trailing garbage appended to a cache file, or a section size corrupted to under-count.","commonSituations":"Append-style writes that left stale bytes at the end; partial overwrite that shrank a section without updating the header; tools that `>>` appended to the cache file; cache file reused across incompatible formats.","solutions":["Delete the cache file and regenerate.","Ensure cache writes are atomic (write-tmp-then-rename) — webpack does this; bypassing it (external copy) can leave trailing bytes.","Make sure nothing appends to cache files.","Confirm a single webpack version owns the cache."],"exampleFix":"// before: trailing bytes after section table -> offset != buf.length\n// after\n//   rm -rf node_modules/.cache/webpack && yarn webpack","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"compiler.hooks.failed.tap('CacheCorruptionGuard', (err) => {\n  if (/Section table does not match file size/.test(err.message)) {\n    require('fs').rmSync(cacheLocation, { recursive: true, force: true });\n  }\n});","preventionTips":["Never append to cache files externally.","Keep webpack's atomic write-then-rename intact.","One webpack version per cache location."],"tags":["serialization","cache","corruption","fs","persistence"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}