Hello, I found a bug in dwg2dxf.

## environment

- ubuntu 20.04, GCC 9.4.0, libredwg latest commit https://github.com/LibreDWG/libredwg/commit/b9795eaac10bdfb0394f959ea39b1d00750c3a46
- not reproducible on the release 0.12.5


compile with ASAN

```
export CFLAGS="-fsanitize=address -g"
export CXXFLAGS="-fsanitize=address -g"
./autogen.sh && ./configure --disable-shared && make -j$(nproc)
```

## ASAN LOG

reproduce command: ` ./dwg2dxf $PoC`

```
root@b6092ec2626f:/libredwg/programs# ./dwg2dxf /dwg2dxf_poc2
Reading DWG file /dw2dxf_poc2
=================================================================
==54463==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000f2 at pc 0x560b164dbddc bp 0x7ffdb3029fd0 sp 0x7ffdb3029fc0
READ of size 2 at 0x6020000000f2 thread T0
    #0 0x560b164dbddb in dwg_section_wtype /libredwg/src/dwg.c:1806
    #1 0x560b17316b81 in read_sections_map /libredwg/src/decode_r2007.c:957
    #2 0x560b173794a7 in read_r2007_meta_data /libredwg/src/decode_r2007.c:2388
    #3 0x560b165b11f6 in decode_R2007 /libredwg/src/decode.c:3480
    #4 0x560b16509de6 in dwg_decode /libredwg/src/decode.c:235
    #5 0x560b164d1369 in dwg_read_file /libredwg/src/dwg.c:268
    #6 0x560b164ceed8 in main /libredwg/programs/dwg2dxf.c:261
    #7 0x7fc30853a082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
    #8 0x560b164cdd6d in _start (/libredwg/programs/dwg2dxf+0x25cd6d)

0x6020000000f3 is located 0 bytes to the right of 3-byte region [0x6020000000f0,0x6020000000f3)
allocated by thread T0 here:
    #0 0x7fc308964a06 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
    #1 0x560b173168bb in read_sections_map /libredwg/src/decode_r2007.c:946
    #2 0x560b173794a7 in read_r2007_meta_data /libredwg/src/decode_r2007.c:2388
    #3 0x560b165b11f6 in decode_R2007 /libredwg/src/decode.c:3480
    #4 0x560b16509de6 in dwg_decode /libredwg/src/decode.c:235
    #5 0x560b164d1369 in dwg_read_file /libredwg/src/dwg.c:268
    #6 0x560b164ceed8 in main /libredwg/programs/dwg2dxf.c:261
    #7 0x7fc30853a082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)

SUMMARY: AddressSanitizer: heap-buffer-overflow /libredwg/src/dwg.c:1806 in dwg_section_wtype
Shadow bytes around the buggy address:
  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff8000: fa fa fd fd fa fa 00 00 fa fa 00 fa fa fa 00 fa
=>0x0c047fff8010: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa[03]fa
  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8060: 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
  Shadow gap:              cc
==54463==ABORTING
```

## PoC 

[PoC.zip](https://github.com/LibreDWG/libredwg/files/13699532/PoC.zip)

[FUZZ] Heap buffer overflow  in decode r2007, dwg_section_wtype
This is a GitHub Issue
repo:libredwg
owner:LibreDWG
Title : [FUZZ] Heap buffer overflow  in decode r2007, dwg_section_wtype
Issue date:

--- start body ---
Hello, I found a bug in dwg2dxf.

## environment

- ubuntu 20.04, GCC 9.4.0, libredwg latest commit https://github.com/LibreDWG/libredwg/commit/b9795eaac10bdfb0394f959ea39b1d00750c3a46
- not reproducible on the release 0.12.5


compile with ASAN

```
export CFLAGS="-fsanitize=address -g"
export CXXFLAGS="-fsanitize=address -g"
./autogen.sh && ./configure --disable-shared && make -j$(nproc)
```

## ASAN LOG

reproduce command: ` ./dwg2dxf $PoC`

```
root@b6092ec2626f:/libredwg/programs# ./dwg2dxf /dwg2dxf_poc2
Reading DWG file /dw2dxf_poc2
=================================================================
==54463==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000f2 at pc 0x560b164dbddc bp 0x7ffdb3029fd0 sp 0x7ffdb3029fc0
READ of size 2 at 0x6020000000f2 thread T0
    #0 0x560b164dbddb in dwg_section_wtype /libredwg/src/dwg.c:1806
    #1 0x560b17316b81 in read_sections_map /libredwg/src/decode_r2007.c:957
    #2 0x560b173794a7 in read_r2007_meta_data /libredwg/src/decode_r2007.c:2388
    #3 0x560b165b11f6 in decode_R2007 /libredwg/src/decode.c:3480
    #4 0x560b16509de6 in dwg_decode /libredwg/src/decode.c:235
    #5 0x560b164d1369 in dwg_read_file /libredwg/src/dwg.c:268
    #6 0x560b164ceed8 in main /libredwg/programs/dwg2dxf.c:261
    #7 0x7fc30853a082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
    #8 0x560b164cdd6d in _start (/libredwg/programs/dwg2dxf+0x25cd6d)

0x6020000000f3 is located 0 bytes to the right of 3-byte region [0x6020000000f0,0x6020000000f3)
allocated by thread T0 here:
    #0 0x7fc308964a06 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
    #1 0x560b173168bb in read_sections_map /libredwg/src/decode_r2007.c:946
    #2 0x560b173794a7 in read_r2007_meta_data /libredwg/src/decode_r2007.c:2388
    #3 0x560b165b11f6 in decode_R2007 /libredwg/src/decode.c:3480
    #4 0x560b16509de6 in dwg_decode /libredwg/src/decode.c:235
    #5 0x560b164d1369 in dwg_read_file /libredwg/src/dwg.c:268
    #6 0x560b164ceed8 in main /libredwg/programs/dwg2dxf.c:261
    #7 0x7fc30853a082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)

SUMMARY: AddressSanitizer: heap-buffer-overflow /libredwg/src/dwg.c:1806 in dwg_section_wtype
Shadow bytes around the buggy address:
  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff8000: fa fa fd fd fa fa 00 00 fa fa 00 fa fa fa 00 fa
=>0x0c047fff8010: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa[03]fa
  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8060: 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
  Shadow gap:              cc
==54463==ABORTING
```

## PoC 

[PoC.zip](https://github.com/LibreDWG/libredwg/files/13699532/PoC.zip)

--- end body ---
