{"record":{"id":"fc78dc734344ac84","repo":"Yalantis/uCrop","slug":"load-png-failed-to-initialize-end-info-struct","errorCode":null,"errorMessage":"load_png(): Failed to initialize 'end_info' structure for file '%s'.","messagePattern":"load_png\\(\\): Failed to initialize 'end_info' structure for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57416,"sourceCode":"        throw CImgIOException(_cimg_instance\n                              \"load_png(): Failed to initialize 'png_ptr' structure for file '%s'.\",\n                              cimg_instance,\n                              nfilename?nfilename:\"(FILE*)\");\n      }\n      png_infop info_ptr = png_create_info_struct(png_ptr);\n      if (!info_ptr) {\n        if (!file) cimg::fclose(nfile);\n        png_destroy_read_struct(&png_ptr,(png_infopp)0,(png_infopp)0);\n        throw CImgIOException(_cimg_instance\n                              \"load_png(): Failed to initialize 'info_ptr' structure for file '%s'.\",\n                              cimg_instance,\n                              nfilename?nfilename:\"(FILE*)\");\n      }\n      png_infop end_info = png_create_info_struct(png_ptr);\n      if (!end_info) {\n        if (!file) cimg::fclose(nfile);\n        png_destroy_read_struct(&png_ptr,&info_ptr,(png_infopp)0);\n        throw CImgIOException(_cimg_instance\n                              \"load_png(): Failed to initialize 'end_info' structure for file '%s'.\",\n                              cimg_instance,\n                              nfilename?nfilename:\"(FILE*)\");\n      }\n\n      // Error handling callback for png file reading.\n      if (setjmp(png_jmpbuf(png_ptr))) {\n        if (!file) cimg::fclose((std::FILE*)nfile);\n        png_destroy_read_struct(&png_ptr, &end_info, (png_infopp)0);\n        throw CImgIOException(_cimg_instance\n                              \"load_png(): Encountered unknown fatal error in libpng for file '%s'.\",\n                              cimg_instance,\n                              nfilename?nfilename:\"(FILE*)\");\n      }\n      png_init_io(png_ptr, nfile);\n      png_set_sig_bytes(png_ptr, 8);\n\n      // Get PNG Header Info up to data block.","sourceCodeStart":57398,"sourceCodeEnd":57434,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57398-L57434","documentation":"Thrown by CImg<T>::load_png() when the second png_create_info_struct() call (for the end-info structure) returns null; both previously created structures (png_ptr and info_ptr) are destroyed via png_destroy_read_struct before the exception is raised.","triggerScenarios":"Allocation failure while creating the third libpng structure (end_info) during load_png(); same OOM/fragmentation conditions as the other init failures.","commonSituations":"Low-memory processes, memory-constrained mobile/embedded builds, or near-exhausted heaps after many image operations.","solutions":["Free memory and retry.","Lower peak memory usage (load images sequentially, resize before caching).","Rebuild/upgrade libpng to a consistent, current version."],"exampleFix":"// before\nimg.load_png(path); // throws when end_info allocation fails\n// after\nimg.clear();\nimg.load_png(path);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { img.load_png(path); }\ncatch (CImgIOException &e) {\n  std::fprintf(stderr, \"libpng end_info init failed: %s\\n\", e.what());\n}","preventionTips":["Load images one at a time in memory-constrained code","Release image buffers promptly (assign()/clear())","Keep libpng versions consistent between headers and library"],"tags":["cimg","libpng","memory","initialization"],"backgroundTag":"module-init-failed","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"}