{"record":{"id":"86662a2021a1cce5","repo":"Yalantis/uCrop","slug":"load-pfm-pfm-header-not-found-in-file-s","errorCode":null,"errorMessage":"load_pfm(): PFM header not found in file '%s'.","messagePattern":"load_pfm\\(\\): PFM header not found in file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57783,"sourceCode":"    static CImg<T> get_load_pfm(std::FILE *const file) {\n      return CImg<T>().load_pfm(file);\n    }\n\n    CImg<T>& _load_pfm(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_pfm(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      char pfm_type;\n      CImg<charT> item(16384,1,1,1,0);\n      int W = 0, H = 0, err = 0;\n      double scale = 0;\n      while ((err=std::fscanf(nfile,\"%16383[^\\n]\",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);\n      if (cimg_sscanf(item,\" P%c\",&pfm_type)!=1) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_pfm(): PFM header not found in file '%s'.\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\");\n      }\n      while ((err=std::fscanf(nfile,\" %16383[^\\n]\",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);\n      if ((err=cimg_sscanf(item,\" %d %d\",&W,&H))<2) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_pfm(): WIDTH and HEIGHT fields are undefined in file '%s'.\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\");\n      } else if (W<=0 || H<=0) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_pfm(): WIDTH (%d) and HEIGHT (%d) fields are invalid in file '%s'.\",\n                              cimg_instance,W,H,\n                              filename?filename:\"(FILE*)\");\n      }","sourceCodeStart":57765,"sourceCodeEnd":57801,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57765-L57801","documentation":"load_pfm() parses Portable FloatMap headers, expecting the first non-comment line to match the magic 'P<character>' (Pf for grayscale, PF for RGB). If the leading line does not parse as a PFM magic token, the file is not recognized as PFM and CImgIOException is thrown.","triggerScenarios":"Calling load_pfm() on files whose first line is not 'PF' or 'Pf': a PNM/PGM file passed to the PFM loader, a corrupted or truncated PFM, a file with a BOM or leading junk, or an empty file.","commonSituations":"Mixing up load_pnm and load_pfm for similar-looking formats; HDRI pipeline files truncated mid-upload; tools writing PFM with a Windows BOM or leading whitespace.","solutions":["Verify the file starts with 'PF' or 'Pf' (e.g. `head -c 2 file.pfm`).","Use the correct loader for the actual format (load_pnm for P1-P6 files).","Re-export the HDR image as PFM with a known tool (`convert hdr.exr out.pfm`).","Strip BOM/leading whitespace before the magic token.","Catch CImgIOException and report the file as non-PFM."],"exampleFix":"// before\nimg.load_pfm(path); // actually a PGM\n// after\nstd::ifstream f(path, std::ios::binary);\nchar m[2] = {0}; f.read(m, 2);\nif (m[0]=='P' && (m[1]=='F' || m[1]=='f')) img.load_pfm(path);\nelse img.load_pnm(path);","handlingStrategy":"validation","validationCode":"bool looksLikePfm(const char* path) {\n  std::ifstream f(path, std::ios::binary);\n  char m[2] = {0};\n  f.read(m, 2);\n  return f && m[0]=='P' && (m[1]=='F' || m[1]=='f');\n}","typeGuard":"bool isPfmMagic(const unsigned char* b, size_t n) {\n  return n >= 2 && b[0]=='P' && (b[1]=='F' || b[1]=='f');\n}","tryCatchPattern":"try {\n  img.load_pfm(path);\n} catch (cimg_library::CImgIOException& e) {\n  std::cerr << \"Not a PFM file: \" << e.what() << \"\\n\";\n}","preventionTips":["Check for 'PF'/'Pf' magic before load_pfm","Don't feed PNM files to the PFM loader (and vice versa)","Write PFMs without BOM or leading junk","Route format detection through load() instead of a hard-coded loader"],"tags":["cimg","pfm","image-loading","malformed-header"],"backgroundTag":"invalid-argument-format","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}