Hi,
In release version 0.12.4, (also in the latest commit 45d2a29)

There is heapbuffer-overflow in function dwg_encode_STYLE_private() in dwg.spec

**reproduce**
./configure --enable-release
CFLAGS="-fsanitize=address" ./configure --enable-release
make
./dwgrewrite [poc]

[heap-buffer-overflow_dwg_encode_STYLE_private.zip](https://github.com/LibreDWG/libredwg/files/6622024/heap-buffer-overflow_dwg_encode_STYLE_private.zip)

```c
 AddressSanitizer: heap-buffer-overflow on address 0x6020000020a0 at pc 0x562610b3fe1f bp 0x7ffeebfe3ae0 sp 0x7ffeebfe3ad0
READ of size 8 at 0x6020000020a0 thread T0
    #0 0x562610b3fe1e in dwg_encode_STYLE_private /home/chiba/libredwg-check/src/dwg.spec:3047
    #1 0x562610b3ef8e in dwg_encode_STYLE /home/chiba/libredwg-check/src/dwg.spec:3045
    #2 0x5626118b3912 in dwg_encode_add_object /home/chiba/libredwg-check/src/encode.c:3667
    #3 0x5626108a2eb6 in dwg_encode /home/chiba/libredwg-check/src/encode.c:2352
    #4 0x56260f65e78d in dwg_write_file /home/chiba/libredwg-check/src/dwg.c:429
    #5 0x56260f65af4f in main /home/chiba/libredwg-check/programs/dwgrewrite.c:349
    #6 0x7fd6bdaa50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #7 0x56260f659bad in _start (/home/chiba/libredwg-check/asan-master/bin/dwgrewrite+0x207bad)

0x6020000020a0 is located 8 bytes to the right of 8-byte region [0x602000002090,0x602000002098)
allocated by thread T0 here:
    #0 0x7fd6bdeccdc6 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10ddc6)
    #1 0x56260fc3f748 in dwg_setup_UNKNOWN_OBJ /home/chiba/libredwg-check/src/dwg.spec:7005
    #2 0x56260fc3fcb5 in dwg_decode_UNKNOWN_OBJ /home/chiba/libredwg-check/src/dwg.spec:7005
    #3 0x5626101c19b8 in dwg_decode_add_object /home/chiba/libredwg-check/src/decode.c:5900
    #4 0x56260f72435f in read_2004_section_handles /home/chiba/libredwg-check/src/decode.c:2928
    #5 0x56260f77dfd0 in decode_R2004 /home/chiba/libredwg-check/src/decode.c:3778
    #6 0x56260f686735 in dwg_decode /home/chiba/libredwg-check/src/decode.c:252
    #7 0x56260f65cb78 in dwg_read_file /home/chiba/libredwg-check/src/dwg.c:254
    #8 0x56260f65ab44 in main /home/chiba/libredwg-check/programs/dwgrewrite.c:290
    #9 0x7fd6bdaa50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/chiba/libredwg-check/src/dwg.spec:3047 in dwg_encode_STYLE_private
Shadow bytes around the buggy address:
  0x0c047fff83c0: fa fa 00 fa fa fa 00 04 fa fa 00 fa fa fa 00 fa
  0x0c047fff83d0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff83e0: fa fa 00 fa fa fa 00 02 fa fa 00 fa fa fa 00 04
  0x0c047fff83f0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8400: fa fa 02 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
=>0x0c047fff8410: fa fa 00 fa[fa]fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8420: fa fa 00 fa fa fa 00 fa fa fa 02 fa fa fa 00 fa
  0x0c047fff8430: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8440: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8450: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8460: fa fa 00 fa fa fa 00 fa fa fa 04 fa fa fa 00 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
==2429575==ABORTING

```
heap-buffer-overflow in dwg_encode_STYLE_private() in dwg.spec
This is a GitHub Issue
repo:libredwg
owner:LibreDWG
Title : heap-buffer-overflow in dwg_encode_STYLE_private() in dwg.spec
Issue date:

--- start body ---
Hi,
In release version 0.12.4, (also in the latest commit 45d2a29)

There is heapbuffer-overflow in function dwg_encode_STYLE_private() in dwg.spec

**reproduce**
./configure --enable-release
CFLAGS="-fsanitize=address" ./configure --enable-release
make
./dwgrewrite [poc]

[heap-buffer-overflow_dwg_encode_STYLE_private.zip](https://github.com/LibreDWG/libredwg/files/6622024/heap-buffer-overflow_dwg_encode_STYLE_private.zip)

```c
 AddressSanitizer: heap-buffer-overflow on address 0x6020000020a0 at pc 0x562610b3fe1f bp 0x7ffeebfe3ae0 sp 0x7ffeebfe3ad0
READ of size 8 at 0x6020000020a0 thread T0
    #0 0x562610b3fe1e in dwg_encode_STYLE_private /home/chiba/libredwg-check/src/dwg.spec:3047
    #1 0x562610b3ef8e in dwg_encode_STYLE /home/chiba/libredwg-check/src/dwg.spec:3045
    #2 0x5626118b3912 in dwg_encode_add_object /home/chiba/libredwg-check/src/encode.c:3667
    #3 0x5626108a2eb6 in dwg_encode /home/chiba/libredwg-check/src/encode.c:2352
    #4 0x56260f65e78d in dwg_write_file /home/chiba/libredwg-check/src/dwg.c:429
    #5 0x56260f65af4f in main /home/chiba/libredwg-check/programs/dwgrewrite.c:349
    #6 0x7fd6bdaa50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #7 0x56260f659bad in _start (/home/chiba/libredwg-check/asan-master/bin/dwgrewrite+0x207bad)

0x6020000020a0 is located 8 bytes to the right of 8-byte region [0x602000002090,0x602000002098)
allocated by thread T0 here:
    #0 0x7fd6bdeccdc6 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10ddc6)
    #1 0x56260fc3f748 in dwg_setup_UNKNOWN_OBJ /home/chiba/libredwg-check/src/dwg.spec:7005
    #2 0x56260fc3fcb5 in dwg_decode_UNKNOWN_OBJ /home/chiba/libredwg-check/src/dwg.spec:7005
    #3 0x5626101c19b8 in dwg_decode_add_object /home/chiba/libredwg-check/src/decode.c:5900
    #4 0x56260f72435f in read_2004_section_handles /home/chiba/libredwg-check/src/decode.c:2928
    #5 0x56260f77dfd0 in decode_R2004 /home/chiba/libredwg-check/src/decode.c:3778
    #6 0x56260f686735 in dwg_decode /home/chiba/libredwg-check/src/decode.c:252
    #7 0x56260f65cb78 in dwg_read_file /home/chiba/libredwg-check/src/dwg.c:254
    #8 0x56260f65ab44 in main /home/chiba/libredwg-check/programs/dwgrewrite.c:290
    #9 0x7fd6bdaa50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/chiba/libredwg-check/src/dwg.spec:3047 in dwg_encode_STYLE_private
Shadow bytes around the buggy address:
  0x0c047fff83c0: fa fa 00 fa fa fa 00 04 fa fa 00 fa fa fa 00 fa
  0x0c047fff83d0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff83e0: fa fa 00 fa fa fa 00 02 fa fa 00 fa fa fa 00 04
  0x0c047fff83f0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8400: fa fa 02 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
=>0x0c047fff8410: fa fa 00 fa[fa]fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8420: fa fa 00 fa fa fa 00 fa fa fa 02 fa fa fa 00 fa
  0x0c047fff8430: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8440: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8450: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
  0x0c047fff8460: fa fa 00 fa fa fa 00 fa fa fa 04 fa fa fa 00 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
==2429575==ABORTING

```
--- end body ---
