## Affected version 

the latest commit: https://github.com/LibreDWG/libredwg/tree/45d2a290c65ed691be0901ba2b2ef51044e07a16 and 0.12.4

## What's the problem?


A heap buffer overflow was discovered in dxf_tables_read  in in_dxf.c:11968.

ASAN report:

```
==2899325==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000001ca8 at pc 0x000001a74abb bp 0x7fffffffc990 sp 0x7fffffffc988
READ of size 8 at 0x603000001ca8 thread T0
    #0 0x1a74aba in dxf_tables_read /src/libredwg/src/in_dxf.c:11968:54
    #1 0x1a6ce22 in dwg_read_dxf /src/libredwg/src/in_dxf.c:12779:23
    #2 0x4cb82a in dxf_read_file /src/libredwg/src/dwg.c:381:13
    #3 0x4c91c4 in main /src/libredwg/programs/dxf2dwg.c:312:15
    #4 0x7ffff7c580b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
    #5 0x41c40d in _start (/mnt/disk/out/libredwg/programs_asan/dxf2dwg+0x41c40d)

0x603000001ca8 is located 244 bytes to the right of 20-byte region [0x603000001ba0,0x603000001bb4)
allocated by thread T0 here:
    #0 0x483614 in strdup /src/llvm-project-12.0.0.src/compiler-rt/lib/asan/asan_interceptors.cpp:437:3
    #1 0x1a685b1 in array_push /src/libredwg/src/in_dxf.c:730:25
    #2 0x1ad02a4 in add_eed /src/libredwg/src/in_dxf.c:1763:26
    #3 0x1a96958 in new_object /src/libredwg/src/in_dxf.c:10041:13
    #4 0x1a73b0a in dxf_tables_read /src/libredwg/src/in_dxf.c:11909:22
    #5 0x1a6ce22 in dwg_read_dxf /src/libredwg/src/in_dxf.c:12779:23
    #6 0x4cb82a in dxf_read_file /src/libredwg/src/dwg.c:381:13
    #7 0x4c91c4 in main /src/libredwg/programs/dxf2dwg.c:312:15
    #8 0x7ffff7c580b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /src/libredwg/src/in_dxf.c:11968:54 in dxf_tables_read
Shadow bytes around the buggy address:
  0x0c067fff8340: 02 fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa
  0x0c067fff8350: fd fd fd fa fa fa 00 00 06 fa fa fa 00 00 04 fa
  0x0c067fff8360: fa fa fd fd fd fa fa fa 00 00 03 fa fa fa fd fd
  0x0c067fff8370: fd fa fa fa 00 00 04 fa fa fa fa fa fa fa fa fa
  0x0c067fff8380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff8390: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83e0: 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
==2899325==ABORTING
```


## Compile command

```
CC="clang" CFLAGS="-O1 -g -fsanitize=address" ./configure --enable-release --disable-shared && make
```

## How can we reproduce the issue?

```
unzip tests_64241.zip
dxf2dwg ./tests_64241 -o /dev/null
```
POC file :  
[tests_64241.zip](https://github.com/LibreDWG/libredwg/files/6629665/tests_64241.zip)


Heap-buffer-overflow in dxf_tables_read in in_dxf.c
This is a GitHub Issue
repo:libredwg
owner:LibreDWG
Title : Heap-buffer-overflow in dxf_tables_read in in_dxf.c
Issue date:

--- start body ---
## Affected version 

the latest commit: https://github.com/LibreDWG/libredwg/tree/45d2a290c65ed691be0901ba2b2ef51044e07a16 and 0.12.4

## What's the problem?


A heap buffer overflow was discovered in dxf_tables_read  in in_dxf.c:11968.

ASAN report:

```
==2899325==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000001ca8 at pc 0x000001a74abb bp 0x7fffffffc990 sp 0x7fffffffc988
READ of size 8 at 0x603000001ca8 thread T0
    #0 0x1a74aba in dxf_tables_read /src/libredwg/src/in_dxf.c:11968:54
    #1 0x1a6ce22 in dwg_read_dxf /src/libredwg/src/in_dxf.c:12779:23
    #2 0x4cb82a in dxf_read_file /src/libredwg/src/dwg.c:381:13
    #3 0x4c91c4 in main /src/libredwg/programs/dxf2dwg.c:312:15
    #4 0x7ffff7c580b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
    #5 0x41c40d in _start (/mnt/disk/out/libredwg/programs_asan/dxf2dwg+0x41c40d)

0x603000001ca8 is located 244 bytes to the right of 20-byte region [0x603000001ba0,0x603000001bb4)
allocated by thread T0 here:
    #0 0x483614 in strdup /src/llvm-project-12.0.0.src/compiler-rt/lib/asan/asan_interceptors.cpp:437:3
    #1 0x1a685b1 in array_push /src/libredwg/src/in_dxf.c:730:25
    #2 0x1ad02a4 in add_eed /src/libredwg/src/in_dxf.c:1763:26
    #3 0x1a96958 in new_object /src/libredwg/src/in_dxf.c:10041:13
    #4 0x1a73b0a in dxf_tables_read /src/libredwg/src/in_dxf.c:11909:22
    #5 0x1a6ce22 in dwg_read_dxf /src/libredwg/src/in_dxf.c:12779:23
    #6 0x4cb82a in dxf_read_file /src/libredwg/src/dwg.c:381:13
    #7 0x4c91c4 in main /src/libredwg/programs/dxf2dwg.c:312:15
    #8 0x7ffff7c580b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /src/libredwg/src/in_dxf.c:11968:54 in dxf_tables_read
Shadow bytes around the buggy address:
  0x0c067fff8340: 02 fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa
  0x0c067fff8350: fd fd fd fa fa fa 00 00 06 fa fa fa 00 00 04 fa
  0x0c067fff8360: fa fa fd fd fd fa fa fa 00 00 03 fa fa fa fd fd
  0x0c067fff8370: fd fa fa fa 00 00 04 fa fa fa fa fa fa fa fa fa
  0x0c067fff8380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff8390: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff83e0: 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
==2899325==ABORTING
```


## Compile command

```
CC="clang" CFLAGS="-O1 -g -fsanitize=address" ./configure --enable-release --disable-shared && make
```

## How can we reproduce the issue?

```
unzip tests_64241.zip
dxf2dwg ./tests_64241 -o /dev/null
```
POC file :  
[tests_64241.zip](https://github.com/LibreDWG/libredwg/files/6629665/tests_64241.zip)


--- end body ---
