Hi,
In release version 0.12.4, (also in the latest commit 4c210bb) 

There is null pointer deference in function read_data_section in decode_r2007.c

Here need check the validity of `section->pages` before useing.
```c
────── source:decode_r2007.c+790 ────
    785	   sec_dat->version = dat->version;
    786	   sec_dat->from_version = dat->from_version;
    787
    788	   for (i = 0; i < (int)section->num_pages; i++)
    789	     {
               // section_page=0x00007fffffffcc20  →  0x00000000ffffd090, section=0x00007fffffffcc08  →  [...]  →  0x000000000000012c, i=0x0
 →  790	       r2007_section_page *section_page = section->pages[i];
    791	       page = get_page (pages_map, section_page->id);
    792	       if (page == NULL)
    793	         {
    794	           free (decomp);
    795	           LOG_ERROR ("Failed to find page %d", (int)section_page->id)
──────────── threads ────
[#0] Id 1, Name: "dwg", stopped 0x555555d10522 in read_data_section (), reason: SIGSEGV
─────────────────── trace ────
[#0] 0x555555d10522 → read_data_section(sec_dat=0x7fffffffcd50, dat=0x7fffffffd090, sections_map=0x55555698d070, pages_map=0x55555698d740, sec_type=SECTION_FILEDEPLIST)
[#1] 0x555555d2329f → read_2007_section_filedeplist(dat=0x7fffffffd090, dwg=0x7fffffffd1a0, sections_map=0x55555698d070, pages_map=0x55555698d740)
[#2] 0x555555d3a2e6 → read_r2007_meta_data(dat=0x7fffffffd090, hdl_dat=0x7fffffffcfd0, dwg=0x7fffffffd1a0)
[#3] 0x555555634d2a → decode_R2007(dat=0x7fffffffd090, dwg=0x7fffffffd1a0)
[#4] 0x5555555bedba → dwg_decode(dat=0x7fffffffd090, dwg=0x7fffffffd1a0)
[#5] 0x5555555adfc0 → dwg_read_file(filename=0x7fffffffe611 "poc", dwg=0x7fffffffd1a0)
[#6] 0x5555555acc65 → main(argc=0x2, argv=0x7fffffffe378)
─────────────────────
```
gef➤  p section->pages
$1 = (r2007_section_page **) 0x0

**reproduce**
./configure --enable-release --disable-shared
make 

./dwgread [poc]

[nullpointer_read_data_section_1.zip](https://github.com/LibreDWG/libredwg/files/6603016/nullpointer_read_data_section_1.zip)







null pointer deference in function read_data_section in decode_r2007.c
This is a GitHub Issue
repo:libredwg
owner:LibreDWG
Title : null pointer deference in function read_data_section in decode_r2007.c
Issue date:

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

There is null pointer deference in function read_data_section in decode_r2007.c

Here need check the validity of `section->pages` before useing.
```c
────── source:decode_r2007.c+790 ────
    785	   sec_dat->version = dat->version;
    786	   sec_dat->from_version = dat->from_version;
    787
    788	   for (i = 0; i < (int)section->num_pages; i++)
    789	     {
               // section_page=0x00007fffffffcc20  →  0x00000000ffffd090, section=0x00007fffffffcc08  →  [...]  →  0x000000000000012c, i=0x0
 →  790	       r2007_section_page *section_page = section->pages[i];
    791	       page = get_page (pages_map, section_page->id);
    792	       if (page == NULL)
    793	         {
    794	           free (decomp);
    795	           LOG_ERROR ("Failed to find page %d", (int)section_page->id)
──────────── threads ────
[#0] Id 1, Name: "dwg", stopped 0x555555d10522 in read_data_section (), reason: SIGSEGV
─────────────────── trace ────
[#0] 0x555555d10522 → read_data_section(sec_dat=0x7fffffffcd50, dat=0x7fffffffd090, sections_map=0x55555698d070, pages_map=0x55555698d740, sec_type=SECTION_FILEDEPLIST)
[#1] 0x555555d2329f → read_2007_section_filedeplist(dat=0x7fffffffd090, dwg=0x7fffffffd1a0, sections_map=0x55555698d070, pages_map=0x55555698d740)
[#2] 0x555555d3a2e6 → read_r2007_meta_data(dat=0x7fffffffd090, hdl_dat=0x7fffffffcfd0, dwg=0x7fffffffd1a0)
[#3] 0x555555634d2a → decode_R2007(dat=0x7fffffffd090, dwg=0x7fffffffd1a0)
[#4] 0x5555555bedba → dwg_decode(dat=0x7fffffffd090, dwg=0x7fffffffd1a0)
[#5] 0x5555555adfc0 → dwg_read_file(filename=0x7fffffffe611 "poc", dwg=0x7fffffffd1a0)
[#6] 0x5555555acc65 → main(argc=0x2, argv=0x7fffffffe378)
─────────────────────
```
gef➤  p section->pages
$1 = (r2007_section_page **) 0x0

**reproduce**
./configure --enable-release --disable-shared
make 

./dwgread [poc]

[nullpointer_read_data_section_1.zip](https://github.com/LibreDWG/libredwg/files/6603016/nullpointer_read_data_section_1.zip)







--- end body ---

A null pointer dereference vulnerability in the function read_data_section of LibreDWG version 0.12.4 can lead to a segmentation fault when the code attempts to access the pages of a section without validating that the pointer is not null. This can be exploited by providing a specially crafted DWG file that causes the application to crash.