Buffer overflow vulnerability in function convert_colorspace in heif_colorconversion.cc in libheif v1.6.2, allows attackers to cause a denial of service and disclose sensitive information, via a crafted HEIF file.
I spotted this overflow in `heif_colorconversion.cc`. 
##### how to reproduce:
```./heif-convert heap-overflow.poc test.png```

[heap-overflow.poc.zip](https://github.com/strukturag/libheif/files/4242885/heap-overflow.poc.zip)

Here is the report of ASAN
```
==19327==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62300000350e at pc 0x0000007cf8f3 bp 0x7ffd1d38dbd0 sp 0x7ffd1d38dbc8
READ of size 2 at 0x62300000350e thread T0
    #0 0x7cf8f2 in Op_YCbCr420_to_RRGGBBaa::convert_colorspace(std::shared_ptr<heif::HeifPixelImage const> const&, heif::ColorState, heif::ColorConversionOptions) libheif/heif_colorconversion.cc:2263:58
    #1 0x7fd4d8 in heif::ColorConversionPipeline::convert_image(std::shared_ptr<heif::HeifPixelImage> const&) libheif/heif_colorconversion.cc:2446:15
    #2 0x781134 in heif::convert_colorspace(std::shared_ptr<heif::HeifPixelImage> const&, heif_colorspace, heif_chroma) libheif/heif_image.cc:396:19
    #3 0x5d4e46 in heif::HeifContext::Image::decode_image(std::shared_ptr<heif::HeifPixelImage>&, heif_colorspace, heif_chroma, heif_decoding_options const*) const libheif/heif_context.cc:896:11
    #4 0x549151 in heif_decode_image libheif/heif.cc:660:33
    #5 0x522111 in main examples/heif_convert.cc:226:11
    #6 0x7f3e8328182f in __libc_start_main /build/glibc-LK5gWL/glibc-2.23/csu/../csu/libc-start.c:291
    #7 0x41e308 in _start (examples/heif-convert+0x41e308)

0x62300000350f is located 0 bytes to the right of 6159-byte region [0x623000001d00,0x62300000350f)
allocated by thread T0 here:
    #0 0x51a178 in operator new[](unsigned long) (examples/heif-convert+0x51a178)
    #1 0x77b052 in heif::HeifPixelImage::add_plane(heif_channel, int, int, int) libheif/heif_image.cc:151:27

SUMMARY: AddressSanitizer: heap-buffer-overflow libheif/heif_colorconversion.cc:2263:58 in Op_YCbCr420_to_RRGGBBaa::convert_colorspace(std::shared_ptr<heif::HeifPixelImage const> const&, heif::ColorState, heif::ColorConversionOptions)
Shadow bytes around the buggy address:
  0x0c467fff8650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c467fff86a0: 00[07]fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19327==ABORTING

```

Heap overflow in heif_colorconversion.cc:2263
This is a GitHub Issue
repo:libheif
owner:strukturag
Title : Heap overflow in heif_colorconversion.cc:2263
Issue date:

--- start body ---
I spotted this overflow in `heif_colorconversion.cc`. 
##### how to reproduce:
```./heif-convert heap-overflow.poc test.png```

[heap-overflow.poc.zip](https://github.com/strukturag/libheif/files/4242885/heap-overflow.poc.zip)

Here is the report of ASAN
```
==19327==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62300000350e at pc 0x0000007cf8f3 bp 0x7ffd1d38dbd0 sp 0x7ffd1d38dbc8
READ of size 2 at 0x62300000350e thread T0
    #0 0x7cf8f2 in Op_YCbCr420_to_RRGGBBaa::convert_colorspace(std::shared_ptr<heif::HeifPixelImage const> const&, heif::ColorState, heif::ColorConversionOptions) libheif/heif_colorconversion.cc:2263:58
    #1 0x7fd4d8 in heif::ColorConversionPipeline::convert_image(std::shared_ptr<heif::HeifPixelImage> const&) libheif/heif_colorconversion.cc:2446:15
    #2 0x781134 in heif::convert_colorspace(std::shared_ptr<heif::HeifPixelImage> const&, heif_colorspace, heif_chroma) libheif/heif_image.cc:396:19
    #3 0x5d4e46 in heif::HeifContext::Image::decode_image(std::shared_ptr<heif::HeifPixelImage>&, heif_colorspace, heif_chroma, heif_decoding_options const*) const libheif/heif_context.cc:896:11
    #4 0x549151 in heif_decode_image libheif/heif.cc:660:33
    #5 0x522111 in main examples/heif_convert.cc:226:11
    #6 0x7f3e8328182f in __libc_start_main /build/glibc-LK5gWL/glibc-2.23/csu/../csu/libc-start.c:291
    #7 0x41e308 in _start (examples/heif-convert+0x41e308)

0x62300000350f is located 0 bytes to the right of 6159-byte region [0x623000001d00,0x62300000350f)
allocated by thread T0 here:
    #0 0x51a178 in operator new[](unsigned long) (examples/heif-convert+0x51a178)
    #1 0x77b052 in heif::HeifPixelImage::add_plane(heif_channel, int, int, int) libheif/heif_image.cc:151:27

SUMMARY: AddressSanitizer: heap-buffer-overflow libheif/heif_colorconversion.cc:2263:58 in Op_YCbCr420_to_RRGGBBaa::convert_colorspace(std::shared_ptr<heif::HeifPixelImage const> const&, heif::ColorState, heif::ColorConversionOptions)
Shadow bytes around the buggy address:
  0x0c467fff8650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c467fff8690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c467fff86a0: 00[07]fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c467fff86f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19327==ABORTING

```

--- end body ---

A heap overflow vulnerability in the `heif_colorconversion.cc` file of the libheif library allows attackers to potentially execute arbitrary code or cause a Denial of Service (DoS) by exploiting the `Op_YCbCr420_to_RRGGBBaa::convert_colorspace` function. This vulnerability can be triggered by providing a specially crafted input file, leading to a buffer overflow during color space conversion.