{"record":{"id":"2989a21a47ea0194","repo":"symfony/translation","slug":"mo-stream-content-has-an-invalid-format","errorCode":null,"errorMessage":"MO stream content has an invalid format.","messagePattern":"MO stream content has an invalid format\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/MoFileLoader.php","lineNumber":49,"sourceCode":"    public const MO_BIG_ENDIAN_MAGIC = 0xDE120495;\n\n    /**\n     * The size of the header of an MO file in bytes.\n     */\n    public const MO_HEADER_SIZE = 28;\n\n    /**\n     * Parses machine object (MO) format, independent of the machine's endian it\n     * was created on. Both 32bit and 64bit systems are supported.\n     */\n    protected function loadResource(string $resource): array\n    {\n        $stream = fopen($resource, 'r');\n\n        $stat = fstat($stream);\n\n        if ($stat['size'] < self::MO_HEADER_SIZE) {\n            throw new InvalidResourceException('MO stream content has an invalid format.');\n        }\n        $magic = unpack('V1', fread($stream, 4));\n        $magic = hexdec(substr(dechex(current($magic)), -8));\n\n        if (self::MO_LITTLE_ENDIAN_MAGIC == $magic) {\n            $isBigEndian = false;\n        } elseif (self::MO_BIG_ENDIAN_MAGIC == $magic) {\n            $isBigEndian = true;\n        } else {\n            throw new InvalidResourceException('MO stream content has an invalid format.');\n        }\n\n        // formatRevision\n        $this->readLong($stream, $isBigEndian);\n        $count = $this->readLong($stream, $isBigEndian);\n        $offsetId = $this->readLong($stream, $isBigEndian);\n        $offsetTranslated = $this->readLong($stream, $isBigEndian);\n        // sizeHashes","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/MoFileLoader.php#L31-L67","documentation":"MoFileLoader reads GNU gettext MO (machine object) files. Before parsing it checks the file is at least MO_HEADER_SIZE bytes; if not, the stream cannot contain a valid MO header and InvalidResourceException is thrown.","triggerScenarios":"loadResource() on an empty, truncated, or non-MO file smaller than the 28-byte MO header — e.g. passing a .po source file where a compiled .mo is expected, or a zero-byte artifact from a failed msgfmt run.","commonSituations":"Deploying .po files instead of compiled .mo files, msgfmt failing silently in CI so empty .mo files get committed, incomplete uploads.","solutions":["Compile the .po catalogues with `msgfmt messages.po -o messages.mo` and deploy the resulting .mo files.","Check the .mo file size: it must be at least 28 bytes; `ls -l` or `wc -c` will reveal empty/truncated files.","Re-run the translation build step and verify it exits 0 before packaging artifacts.","If the file is genuinely corrupt, regenerate it from the .po source or VCS."],"exampleFix":"// before\n$loader->load('messages.po', 'en'); // raw PO, not compiled MO\n// after\nexec('msgfmt messages.po -o messages.mo');\n$loader->load('messages.mo', 'en');","handlingStrategy":"validation","validationCode":"clearstatcache(true, $file);\nif (!is_file($file) || filesize($file) < 28) {\n    throw new \\RuntimeException(sprintf('%s is not a compiled MO file (too small)', $file));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $catalogue = $loader->load($moFile, $locale);\n} catch (InvalidResourceException $e) {\n    error_log('Invalid MO file: '.$e->getMessage());\n    $catalogue = new MessageCatalogue($locale);\n}","preventionTips":["Always compile .po to .mo with msgfmt before deploying","Verify artifact size in your build pipeline","Never commit zero-byte placeholder .mo files","Add a file-size sanity check before addResource"],"tags":["gettext","mo","translation","file-format"],"backgroundTag":"file-read-failed","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}