metanorma / libemf2svg

Microsoft (MS) EMF to SVG conversion library
GNU General Public License v2.0
11 stars 2 forks source link

Windows invalid record - corrupted file? #46

Open stuta opened 1 month ago

stuta commented 1 month ago

Everything works perfectly in OSX, but I can't convert anything but the most simple emf in Windows 11 and Wine in OSX. I'm using https://github.com/mstorsjo/llvm-mingw to compile this project.

I tried with https://github.com/VasiliyLu/Emf2SvgConverter/tree/main/Emf2SvgLibrary/runtimes/win-x64/native -files and they give the same error, so I don't think this is my toolchain problem.

I changed src\lib\emf2svg.c to print more info from the error:

result = U_emf_onerec_draw(contents, blimit, recnum, off, stream, states);
        if (result == (size_t)-1 || states->Error) {
            if (states->verbose) {
                printf("ABORTING(converting): invalid record - corrupted file?, size: %zu, %zu, error: %d\n", result, (size_t)-1, states->Error);
            }

I tried to find the smallest emf, so I'm testing with test-009.emf file. Here is the result:

emf2svg start, input length is: 478

ABORTING(scanning): invalid record - corrupted file?

U_EMR_HEADER                  record:    0 type:1    offset:       0 rsize:     152
   Status:         PARTIAL SUPPORT

...

U_EMR_SELECTOBJECT            record:   15 type:37   offset:     412 rsize:      12
   Status:         PARTIAL SUPPORT
   ihObject:       3

U_EMR_POLYGON16               record:   16 type:86   offset:     424 rsize:     104
ABORTING(converting): invalid record - corrupted file?, size: 18446744073709551615, 18446744073709551615, error: 0

emf2svg done, buffer size is 384, result is 0

The result looks like there is some problem with the result size not being set correctly. Maybe some problems with mixing function result int with unsigned int size; and size_t off?