{"record":{"id":"07ac4f3a84c8053f","repo":"Yalantis/uCrop","slug":"load-yuv-file-s-contains-incomplete-data-or","errorCode":null,"errorMessage":"load_yuv(): File '%s' contains incomplete data or given image dimensions (%u,%u) are incorrect.","messagePattern":"load_yuv\\(\\): File '(.+?)' contains incomplete data or given image dimensions \\(%u,%u\\) are incorrect\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67235,"sourceCode":"      if (nfirst_frame) {\n        err = cimg::fseek(nfile,(uint64T)nfirst_frame*(YUV._width*YUV._height + 2*UV._width*UV._height),SEEK_CUR);\n        if (err) {\n          if (!file) cimg::fclose(nfile);\n          throw CImgIOException(_cimglist_instance\n                                \"load_yuv(): File '%s' doesn't contain frame number %u.\",\n                                cimglist_instance,\n                                filename?filename:\"(FILE*)\",nfirst_frame);\n        }\n      }\n      unsigned int frame;\n      for (frame = nfirst_frame; !stop_flag && frame<=nlast_frame; frame+=nstep_frame) {\n        YUV.get_shared_channel(0).fill(0);\n        // *TRY* to read the luminance part, do not replace by cimg::fread!\n        err = (int)std::fread((void*)(YUV._data),1,(size_t)YUV._width*YUV._height,nfile);\n        if (err!=(int)(YUV._width*YUV._height)) {\n          stop_flag = true;\n          if (err>0)\n            cimg::warn(_cimglist_instance\n                       \"load_yuv(): File '%s' contains incomplete data or given image dimensions \"\n                       \"(%u,%u) are incorrect.\",\n                       cimglist_instance,\n                       filename?filename:\"(FILE*)\",size_x,size_y);\n        } else {\n          UV.fill(0);\n          // *TRY* to read the luminance part, do not replace by cimg::fread!\n          err = (int)std::fread((void*)(UV._data),1,(size_t)UV.size(),nfile);\n          if (err!=(int)(UV.size())) {\n            stop_flag = true;\n            if (err>0)\n              cimg::warn(_cimglist_instance\n                         \"load_yuv(): File '%s' contains incomplete data or given image dimensions \"\n                         \"(%u,%u) are incorrect.\",\n                         cimglist_instance,\n                         filename?filename:\"(FILE*)\",size_x,size_y);\n          } else {\n            const ucharT *ptrs1 = UV._data, *ptrs2 = UV.data(0,0,0,1);","sourceCodeStart":67217,"sourceCodeEnd":67253,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67217-L67253","documentation":"Warning from CImgList<T>::load_yuv() when reading the luminance (Y) plane of a raw YUV video/image file. CImg fread()s exactly width*height bytes for the Y channel; if the returned count differs (but is >0), the loader sets stop_flag and warns that the file contains incomplete data or the requested dimensions (size_x,size_y) are incorrect. The load still returns what was read, so downstream code may see zero-filled/partial data.","triggerScenarios":"Calling load_yuv(filename,size_x,size_y) (or load_yuv with per-frame loop) on a file whose byte count is not a multiple of the expected frame size implied by size_x*size_y and the YUV scheme; most commonly size_x/size_y passed do not match the actual resolution of the raw file, so the Y read hits EOF early.","commonSituations":"Wrong width/height passed to load_yuv for a raw dump (e.g. 640x480 file loaded as 1280x720); raw YUV file truncated during capture/transfer; guessing dimensions instead of knowing the encoder's resolution; reading the last partial frame of a streamed capture.","solutions":["Pass the exact width and height the YUV file was encoded with; confirm with the producer of the raw data.","Check the file size against the expected frame size for the YUV scheme (e.g. 1.5*size_x*size_y for 4:2:0) and re-obtain the file if truncated.","Try candidate resolutions and compare file size modulo frame size to infer the true dimensions.","Validate with a known tool (e.g. ffplay -f rawvideo -pixel_format yuv420p -video_size WxH) before loading in CImg.","Handle the partial read: stop consuming further frames when stop_flag is set and use only fully read frames."],"exampleFix":"// before: dimensions guessed, file is 640x480 4:2:0\nCImgList<ucharT> frames;\nframes.load_yuv(\"capture.yuv\", 1280, 720);\n// after: correct dimensions for the file\nCImgList<ucharT> frames;\nframes.load_yuv(\"capture.yuv\", 640, 480);\n","handlingStrategy":"validation","validationCode":"// Validate file size vs expected YUV frame layout before load_yuv\nstd::error_code ec;\nauto sz = std::filesystem::file_size(path, ec);\nsize_t frameBytes = size_x * size_y * 3 / 2; // 4:2:0\nif (ec || sz == 0 || sz % frameBytes != 0)\n  throw std::runtime_error(\"YUV file size does not match dimensions/scheme\");","typeGuard":null,"tryCatchPattern":"// load_yuv warns instead of throwing; check read completeness\nlist.load_yuv(path, W, H);\n// if warning fired, only fully-read frames are usable; stop consuming further frames","preventionTips":["Never guess width/height for raw YUV; get them from the encoder or probe with ffprobe.","Sanity-check file size against the expected frame byte count for the chroma scheme.","Re-verify transfers of large raw video dumps with checksums.","Expect stop_flag semantics: treat a warned load as truncated and drop the partial frame."],"tags":["cimg","file-parsing","yuv","raw-video"],"backgroundTag":"file-read-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"}