Fix memory corruption on empty raster query (#4778)