CImg icon indicating copy to clipboard operation
CImg copied to clipboard

get_shared_slices() invalid down-cast from size_t to unsigned int

Open crohkohl opened this issue 5 years ago • 2 comments

If you work with very big images the code in get_shared_slices() failes due to integer overflow.

CImg<T> get_shared_slices(const unsigned int z0, const unsigned int z1, const unsigned int c0=0) {
      const unsigned int
        beg = (unsigned int)offset(0,0,z0,c0),
        end = (unsigned int)offset(0,0,z1,c0);
      if (beg>end || beg>=size() || end>=size())
        throw CImgArgumentException(_cimg_instance
                                    "get_shared_slices(): Invalid request of a shared-memory subset "
                                    "(0->%u,0->%u,%u->%u,%u).",
                                    cimg_instance,
                                    _width - 1,_height - 1,z0,z1,c0);

      return CImg<T>(_data + beg,_width,_height,z1 - z0 + 1,1,true);
    }

The result of the offset function should not be casted to unsigned int. There might be other locations in the code where this is a problem.

crohkohl avatar Sep 14 '20 02:09 crohkohl

You are right. This commit should fix this: https://github.com/dtschump/CImg/commit/c56548b31041d352d41fc2ed6f97b8546e5913e3

Let me know if that helps !

dtschump avatar Sep 14 '20 05:09 dtschump

Works perfectly, thank you!

Am Mo., 14. Sept. 2020 um 07:56 Uhr schrieb David Tschumperlé < [email protected]>:

You are right. This commit should fix this: c56548b https://github.com/dtschump/CImg/commit/c56548b31041d352d41fc2ed6f97b8546e5913e3

Let me know if that helps !

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dtschump/CImg/issues/291#issuecomment-691829314, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABU6WQMUXO7D2AP73VYS53TSFWWBZANCNFSM4RLBG6GA .

crohkohl avatar Sep 14 '20 10:09 crohkohl