{"record":{"id":"ecc87ab877b37fa6","repo":"python/cpython","slug":"read-too-short-got-ld-instead-of-ld-bytes","errorCode":null,"errorMessage":"read too short: got %ld instead of %ld bytes\n","messagePattern":"read too short: got %ld instead of %ld bytes\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Programs/_freeze_module.c","lineNumber":112,"sourceCode":"    struct _Py_stat_struct stat;\n    if (_Py_fstat_noraise(fileno(infile), &stat)) {\n        fprintf(stderr, \"cannot fstat '%s'\\n\", inpath);\n        fclose(infile);\n        return NULL;\n    }\n    size_t text_size = (size_t)stat.st_size;\n\n    char *text = (char *) malloc(text_size + 1);\n    if (text == NULL) {\n        fprintf(stderr, \"could not allocate %ld bytes\\n\", (long) text_size);\n        fclose(infile);\n        return NULL;\n    }\n    size_t n = fread(text, 1, text_size, infile);\n    fclose(infile);\n\n    if (n < text_size) {\n        fprintf(stderr, \"read too short: got %ld instead of %ld bytes\\n\",\n                (long) n, (long) text_size);\n        free(text);\n        return NULL;\n    }\n\n    text[text_size] = '\\0';\n    return (const char *)text;\n}\n\nstatic PyObject *\ncompile_and_marshal(const char *name, const char *text)\n{\n    char *filename = (char *) malloc(strlen(name) + 10);\n    if (filename == NULL) {\n        return PyErr_NoMemory();\n    }\n    sprintf(filename, \"<frozen %s>\", name);\n    PyObject *code = Py_CompileStringExFlags(text, filename,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Programs/_freeze_module.c#L94-L130","documentation":"Build-time error from Programs/_freeze_module.c: fread() returned fewer bytes than the stat-reported file size. The file changed (shrank) between fstat and fread, or the read was truncated, so the freezer aborts rather than compiling a partial source file.","triggerScenarios":"The input file is being written concurrently (generated source not finished when the freezer ran); sparse/pseudo files whose stat size does not match readable bytes; disk-full or I/O errors causing a short read.","commonSituations":"Racing build systems that start freezing while a generator still writes the .py; files on network filesystems with inconsistent size vs data; flaky disks.","solutions":["Make the generating step a build dependency that completes before _freeze_module runs (fix dependency ordering in Makefile)","Rerun the build once the file is stable","Move the build to a local filesystem if it happens on NFS/SMB","Check dmesg/Disk health and free space if short reads persist"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# shell: wait until the generated input stops changing before freezing\n# before=$(stat -c %s \"$IN\"); sleep 1; after=$(stat -c %s \"$IN\")\n# [ \"$before\" = \"$after\" ] || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize generators and consumers in the build graph","Use stable filenames plus atomic rename when generating files that freeze steps read","Avoid building on filesystems whose stat/read can disagree"],"tags":["cpython","build","freeze-module","file-race","short-read"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}