{"record":{"id":"9e24248584ee337f","repo":"Yalantis/uCrop","slug":"load-png-failed-to-initialize-info-ptr-struct","errorCode":null,"errorMessage":"load_png(): Failed to initialize 'info_ptr' structure for file '%s'.","messagePattern":"load_png\\(\\): Failed to initialize 'info_ptr' structure for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57407,"sourceCode":"                              nfilename?nfilename:\"(FILE*)\");\n      }\n\n      // Setup PNG structures for read.\n      png_voidp user_error_ptr = 0;\n      png_error_ptr user_error_fn = 0, user_warning_fn = 0;\n      png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,user_error_ptr,user_error_fn,user_warning_fn);\n      if (!png_ptr) {\n        if (!file) cimg::fclose(nfile);\n        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);","sourceCodeStart":57389,"sourceCodeEnd":57425,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57389-L57425","documentation":"Thrown by CImg<T>::load_png() when png_create_info_struct(png_ptr) fails after the main read struct was created: libpng could not allocate the metadata (info) structure; the already-created png_ptr is destroyed before throwing, so no leak remains.","triggerScenarios":"Allocation failure inside libpng (out of memory / fragmented heap) when creating the info struct for a load_png() call.","commonSituations":"Low-memory devices or processes near their memory limit; the same allocation-failure family as the png_ptr error, just one step later.","solutions":["Free memory and retry the load.","Reduce concurrent image allocations in the process.","Ensure a healthy libpng build (consistent versions) and current libpng release.","If it persists, profile the heap for leaks causing the memory pressure."],"exampleFix":"// before\nimg.load_png(\"big.png\"); // throws when info struct allocation fails\n// after\nimg.clear(); // release prior image data before decoding\nimg.load_png(\"big.png\");","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { img.load_png(path); }\ncatch (CImgIOException &e) {\n  std::fprintf(stderr, \"libpng info init failed: %s\\n\", e.what());\n  // free memory, then retry once\n}","preventionTips":["Release previous image buffers before loading new ones","Avoid loading several large images in parallel","Keep libpng up to date and consistently versioned"],"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"}