boostorg / boostorg/gil

kth_channel_view fails when used with virtual views (Trac 9020)

Abierto
#151 2 comentarios 0 reacciones 3 asignados Reclamado por @chhenning Ver en GitHub
status/need-feedback
Lenguaje dominante
C++
Estrellas
199
Forks
171
Merge medio
1 d 14 h
PR fusionados (30 d)
10

Descripción

Moved from https://svn.boost.org/trac10/ticket/9020 description:

> Given an image_view with a `virtual_2d_locator` that returns a `planar_pixel_reference`, `kth_channel_view` produces a `kth_channel_deref_fn` with an incorrect `result_type` which may result an invalid pointer dereference.
>
> For example, consider a `virtual_2d_locator` instantiated with a dereference functor that returns a `planar_pixel_reference`
>
> An image_view instantiated with such a locator will have a reference type of `planar_pixel_reference`. Now suppose this image_view is passed to `kth_channel_view()`. This results in the instantiation of a `kth_channel_deref_fn` with a result_type of `pixel&` however, the deref functor will initialize this result_type with a `pixel&`.
>
> `detail::kth_channel_deref_fn` needs to ensure the channel type of its `result_type` is not a reference type.

Patch:

```
--- image_view_factory.hpp.orig 2013-08-19 12:20:06.000000000 -0500
+++ image_view_factory.hpp 2013-08-19 13:11:49.000000000 -0500
@@ -479,7 +479,8 @@
BOOST_STATIC_CONSTANT(bool, is_mutable=pixel_is_reference::value && pixel_reference_is_mutable::value);
private:
typedef typename remove_reference::type src_pixel_t;
- typedef typename kth_element_type::type channel_t;
+ typedef typename kth_element_type::type channel_ref_t;
+ typedef typename remove_reference::type channel_t;
typedef typename src_pixel_t::const_reference const_ref_t;
typedef typename pixel_reference_type::type ref_t;
public:
```

Example program illustrating the issue:

```
#include
#include
using namespace boost;
using namespace gil;

//
// Do-nothing dereference adaptor
//
template
struct deref_fn {
BOOST_STATIC_CONSTANT(bool, is_mutable=false);
typedef deref_fn const_t;
typedef typename View::value_type value_type;
typedef typename View::reference reference;
typedef typename View::point_t argument_type;
typedef reference result_type;

deref_fn() {;}
deref_fn(const View& v) : mView(v) { ; }
result_type operator()(const argument_type& p) const {
return mView(p);
}

View mView;
};

typedef rgb8_planar_image_t image_t;
typedef image_t::view_t view_t;
typedef deref_fn fn_t;
typedef virtual_2d_locator loc_t;
typedef image_view virt_view_t;
typedef kth_channel_view_type<0, virt_view_t>::type chan0_view_t;

int main(int argc, char **argv) {
image_t img(4,4,rgb8_pixel_t(1,2,3),0);
view_t v(view(img));

fn_t fn(v);
loc_t loc(view_t::point_t(0,0), view_t::point_t(1,1), fn);
virt_view_t virtView(v.dimensions(), loc);

//
// Here detail::kth_channel_deref_fn is instantiated with
// SrcP = 'planar_pixel_reference'. The
// kth_channel_deref_fn then declares its result_type (and thereby
// the chan0_view_t:reference) to be a
// 'pixel&'
//
chan0_view_t chan0View(kth_channel_view<0,virt_view_t>(virtView));

assert((is_same& >::value));

//
// This will typically cause a bus error because the result_type
// of the deref adaptor is a 'pixel&'
// which gets initialized in the deref function by a
// 'pixel&'
//
assert(chan0View(0,0) == gray8_pixel_t(1));
return 0;
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.