Buffer Overflow vulnerability in libming version 0.4.8, allows attackers to execute arbitrary code and obtain sensitive information via parser.c component.
## Environment
Ubuntu 22.04.3 LTS
## Compiler
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
## Affected Version
libming 0.4.8
## Step to reproduce
```cd libming 
./autogen.sh
./configure --disable-shared --disable-freetype
cd util
./swftophp <PoC file>
```
## Contents of PoC file
```
Unzip the file below.
```
[UNZIP_THIS_FILE.zip](https://github.com/libming/libming/files/13604530/UNZIP_THIS_FILE.zip)
## Expected behavior 
Print error or warning messages handled within swftophp.
## Current behavior
```
header indicates a filesize of 117901066 but filesize is 119
<?php
$m = new SWFMovie(10);

ming_setscale(1.0);
$m->setRate(7.027344);
$m->setDimension(0, 0);
$m->setFrames(2055);
 Stream out of sync after parse of blocktype 28 (SWF_REMOVEOBJECT2). 17 but expecting 22.

/* SWF_REMOVEOBJECT2 */
$m->remove($i63495);
 Stream out of sync after parse of blocktype 11 (SWF_DEFINETEXT). 111 but expecting 80.

/* SWF_DEFINETEXT */
$character1799 = new SWFText(1);
$character1799->setColor(0xf0, 0x0a, 0x0a);
outputSWF_TEXT_RECORD: can't process text record: fonts information list is NULL
$character1799->addString("X");
/*Unknown block type 333*/
sudden file end: read failed @107 fileSize 119, request 30

extra garbage (i.e., we messed up in main): 

0000: 46 57 22 22 07 07 07 07  01 01 01 01                FW"".... ....





	header('Content-type: application/x-shockwave-flash');
$m->output(9);
?>

=================================================================
==35188==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x4c4478 in realloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:164:3
    #1 0x557895 in parseSWF_DEFINETEXT /home/libming/util/parser.c:2353:51

Direct leak of 23 byte(s) in 1 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x56bb6d in readBytes /home/libming/util/read.c:252:17

Indirect leak of 624 byte(s) in 1 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53b47a in parseSWF_TEXTRECORD /home/libming/util/parser.c:316:26

Indirect leak of 312 byte(s) in 39 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53a9b8 in parseSWF_GLYPHENTRY /home/libming/util/parser.c:264:25

Indirect leak of 312 byte(s) in 39 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53a6eb in parseSWF_GLYPHENTRY /home/libming/util/parser.c:247:23

SUMMARY: AddressSanitizer: 1319 byte(s) leaked in 81 allocation(s).
```
## Conclusion
If the input file has a manipulated header section, memory leaks occur while parsing the header section in swftophp because parse.c which is the component parsing the header section does not verify that the input file is valid SWF format. 

I will submit a Pull Request to address this issue.
Memory leaks at parser.c:2353:51
This is a GitHub Issue
repo:libming
owner:libming
Title : Memory leaks at parser.c:2353:51
Issue date:

--- start body ---
## Environment
Ubuntu 22.04.3 LTS
## Compiler
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
## Affected Version
libming 0.4.8
## Step to reproduce
```cd libming 
./autogen.sh
./configure --disable-shared --disable-freetype
cd util
./swftophp <PoC file>
```
## Contents of PoC file
```
Unzip the file below.
```
[UNZIP_THIS_FILE.zip](https://github.com/libming/libming/files/13604530/UNZIP_THIS_FILE.zip)
## Expected behavior 
Print error or warning messages handled within swftophp.
## Current behavior
```
header indicates a filesize of 117901066 but filesize is 119
<?php
$m = new SWFMovie(10);

ming_setscale(1.0);
$m->setRate(7.027344);
$m->setDimension(0, 0);
$m->setFrames(2055);
 Stream out of sync after parse of blocktype 28 (SWF_REMOVEOBJECT2). 17 but expecting 22.

/* SWF_REMOVEOBJECT2 */
$m->remove($i63495);
 Stream out of sync after parse of blocktype 11 (SWF_DEFINETEXT). 111 but expecting 80.

/* SWF_DEFINETEXT */
$character1799 = new SWFText(1);
$character1799->setColor(0xf0, 0x0a, 0x0a);
outputSWF_TEXT_RECORD: can't process text record: fonts information list is NULL
$character1799->addString("X");
/*Unknown block type 333*/
sudden file end: read failed @107 fileSize 119, request 30

extra garbage (i.e., we messed up in main): 

0000: 46 57 22 22 07 07 07 07  01 01 01 01                FW"".... ....





	header('Content-type: application/x-shockwave-flash');
$m->output(9);
?>

=================================================================
==35188==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x4c4478 in realloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:164:3
    #1 0x557895 in parseSWF_DEFINETEXT /home/libming/util/parser.c:2353:51

Direct leak of 23 byte(s) in 1 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x56bb6d in readBytes /home/libming/util/read.c:252:17

Indirect leak of 624 byte(s) in 1 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53b47a in parseSWF_TEXTRECORD /home/libming/util/parser.c:316:26

Indirect leak of 312 byte(s) in 39 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53a9b8 in parseSWF_GLYPHENTRY /home/libming/util/parser.c:264:25

Indirect leak of 312 byte(s) in 39 object(s) allocated from:
    #0 0x4c40ff in malloc /home/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x53a6eb in parseSWF_GLYPHENTRY /home/libming/util/parser.c:247:23

SUMMARY: AddressSanitizer: 1319 byte(s) leaked in 81 allocation(s).
```
## Conclusion
If the input file has a manipulated header section, memory leaks occur while parsing the header section in swftophp because parse.c which is the component parsing the header section does not verify that the input file is valid SWF format. 

I will submit a Pull Request to address this issue.
--- end body ---
