{"record":{"id":"668d52db2b7a4c5b","repo":"phacility/phabricator","slug":"integrity-check-failed-new-file-data-differs-from","errorCode":null,"errorMessage":"Integrity check failed: new file data differs from old data!","messagePattern":"Integrity check failed: new file data differs from old data!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php","lineNumber":205,"sourceCode":"        break;\n      case DifferentialHunk::DATATYPE_FILE:\n        $hunk->saveAsFile();\n        break;\n    }\n\n    $this->logOkay(\n      pht('MIGRATE'),\n      pht(\n        'Converted hunk %d to \"%s\" storage (with format \"%s\").',\n        $hunk->getID(),\n        $new_type,\n        $hunk->getDataFormat()));\n\n    $hunk = $this->loadHunk($hunk->getID());\n    $new_data = $hunk->getChanges();\n\n    if ($old_data !== $new_data) {\n      throw new Exception(\n        pht(\n          'Integrity check failed: new file data differs from old data!'));\n    }\n  }\n\n\n}\n","sourceCodeStart":187,"sourceCodeEnd":213,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php#L187-L213","documentation":"After converting a hunk to a new storage type, migrate-hunk reloads the hunk from the database and compares getChanges() against the original data captured before migration. Any byte difference throws this integrity exception, meaning the text->file or file->text conversion corrupted or altered the content. This is a deliberate stop-the-world check: a failure means the storage path (usually file storage for DATATYPE_FILE) is broken or lossy, and the hunk's data is now suspect.","triggerScenarios":"Migrating to DATATYPE_FILE while the Phabricator file storage engine (local disk path or S3/blob backend) is misconfigured, truncating or mangling writes; character-set or escaping corruption on the text path; a partial/interrupted write leaving the hunk half-migrated; bugs in the hunk data-format (compression) round-trip for a specific content shape.","commonSituations":"Storage migrations to S3 with wrong credentials or bucket settings producing empty objects; local file storage directory not writable or full; migrating very large hunks that hit body-size or memory limits; moving between MySQL text columns with differing charset settings.","solutions":["Check the Daemons/file storage config (phabricator.file-storage backend) and verify a test file round-trips: upload and re-download a file","Inspect the affected hunk directly: compare SELECT changes against the stored file blob; re-migrate back with --to text if the text copy is intact","Free disk space / fix S3 credentials or bucket policy, then re-run './bin/differential migrate-hunk --id <id> --to text' to restore textual storage","If content is genuinely lost, restore the row from a backup (differential_hunk and the file blobs) and report the incident upstream with the hunk ID and formats involved","Before bulk migrations, always run a --dry-run pass and keep database + file-storage backups"],"exampleFix":"// Not a code fix: this exception indicates data corruption, not API misuse.\n// Recovery sequence:\n// 1) ./bin/storage dump --out backup.sql  (or restore point)\n// 2) Inspect: SELECT id, dataType, dataFormat, changes FROM differential_hunk WHERE id = <id>;\n// 3) If file-backed copy is corrupt, re-migrate the hunk back:\n//    phabricator/ $ ./bin/differential migrate-hunk --id <id> --to text\n// 4) Fix the underlying file-storage configuration before retrying --to file.","handlingStrategy":"try-catch","validationCode":"// Before any --to file migration, verify file storage round-trips\n$test = PhabricatorFile::newFromFileData('integrity-probe-'.time(), array('name' => 'probe.txt'));\nif ($test->loadFileData() !== 'integrity-probe-'.time()) {\n  throw new Exception('File storage backend is not round-trip safe; abort migration.');\n}","typeGuard":null,"tryCatchPattern":"foreach ($hunk_ids as $id) {\n  try {\n    // migrate one hunk at a time so a failure isolates to a single row\n    // ./bin/differential migrate-hunk --id $id --to file\n  } catch (Exception $ex) {\n    // Integrity failure: STOP the batch, snapshot/backup the affected hunk,\n    // re-migrate that hunk back with --to text, and investigate file storage.\n  }\n}","preventionTips":["Take a full database and file-storage backup before any hunk migration","Migrate a small canary set with --id and verify diffs render before running --all","Confirm disk space and S3/blob backend credentials/quotas beforehand","Run a file upload+download round-trip probe before choosing --to file","Never continue a bulk migration after an integrity failure; treat it as corruption until proven otherwise"],"tags":["phabricator","differential","migrate-hunk","data-integrity","storage","corruption","file-storage"],"backgroundTag":"data-integrity-check-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}