NO

Author Topic: miniz 3.0.2  (Read 6179 times)

Offline John Z

  • Member
  • *
  • Posts: 860
miniz 3.0.2
« on: October 21, 2024, 12:45:57 PM »
A couple years ago (4?) I hacked miniz 1.19 to get it to run under Pelles C.  It still works under Pelles V12 even with the abundant warnings...

Now I see miniz 3.0.2 is out there.  Tried some quick changes as I made in 1.19 but getting:
fatal error: Internal error: 'Access violation' at 0x00007ff7f5333e99  when compiling with Pelles C 12

https://github.com/kuba--/zip

Would be nice if someone has already got it working :) ?? hope hope hope --

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: miniz 3.0.2
« Reply #1 on: October 21, 2024, 08:33:03 PM »
Can't help   :(

internal error comes with x64

Pelles C: with C11
Code: [Select]
struct tm * localtime_s(const time_t * restrict timer, struct tm * restrict dst);
msvc:
Code: [Select]
errno_t localtime_s(struct tm* const tmDest, time_t const* const sourceTime);
so have to define _POSIX_C_SOURCE

My test defines for x86 was: _POSIX_C_SOURCE _wstat64=_wstat _stat64=_stat __stat64=_stat _chsize_s=chsize
x64 have stat64 and wstat64 in crt64

low interest to split source for testing  :(


EDIT:
test with:
Code: [Select]
//#define MINIZ_HEADER_FILE_ONLY // OK
#define MINIZ_NO_ARCHIVE_APIS
#define MINIZ_NO_ARCHIVE_WRITING_APIS
#define MINIZ_NO_STDIO
#define MINIZ_NO_TIME
#define MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
#define MINIZ_NO_INFLATE_APIS
#define MINIZ_NO_MALLOC
#define MINIZ_UNALIGNED_USE_MEMCPY
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES
//#define MINIZ_NO_DEFLATE_APIS // fatal error inside this code
#include "miniz.h"
errors
Code: [Select]
Building test_1.obj.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(689): error #1021: Invalid operand '&&' in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(689): error #1019: Syntax error in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(2957): error #1021: Invalid operand '&&' in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(2957): error #1019: Syntax error in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(3261): error #1019: Syntax error in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(3385): error #1021: Invalid operand '&&' in preprocessor expression.
C:\code\PellesC\MiniZ\zip-v3.0.2\src\miniz.h(3385): error #1019: Syntax error in preprocessor expression.
fatal error: Internal error: 'Access violation' at 0x000000013f703e99.
*** Error code: 1 ***
Done.

so split code to header miniz.h miniz_tdef.c and miniz_tinfl.c for using it

split code from
MINIZ_NO_ARCHIVE_APIS
MINIZ_NO_ARCHIVE_WRITING_APIS

this was one problem, that need modification
Code: [Select]
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
static void mz_zip_time_t_to_dos_time(MZ_TIME_T time, mz_uint16 *pDOS_time,
                                      mz_uint16 *pDOS_date) {
#ifdef __POCC__
  struct tm *tm = localtime(&time);
#elif_MSC_VER
  struct tm tm_struct;
  struct tm *tm = &tm_struct;
  errno_t err = localtime_s(tm, &time);
  if (err) {
    *pDOS_date = 0;
    *pDOS_time = 0;
    return;
  }
#else
  struct tm *tm = localtime(&time);
#endif /* #ifdef _MSC_VER */

EDIT:
compiler crash in function
Code: [Select]
static mz_bool tdefl_compress_normal(
« Last Edit: October 23, 2024, 07:00:49 AM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #2 on: October 21, 2024, 11:53:45 PM »
Thanks Timo, appreciate the look see.

Not urgent anyway so I’ll keep looking as time and interest permits.
Appreciate the defines tip.

There are certainly a lot more interesting things these days  :)

John Z

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: miniz 3.0.2
« Reply #3 on: October 22, 2024, 09:50:38 AM »
Msys2 can compile the code. It creates a library named libzip.a
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #4 on: October 22, 2024, 11:28:07 AM »
Msys2 can compile the code. It creates a library named libzip.a

Thanks Vortex - interesting I've not heard of Msys2 but looking at it now, it is interesting.  I've used Cygwin in the past when working with X-windows on MS-Windows.

this was one problem, that need modification mz_zip_time_t_to_dos_time

Thanks TimoVJL - this one  I recall from before.  Also thanks for the added info for the best split-outs.

I'm thinking about the several approaches ... and the time involved.

John Z

I also now recall from last year that statements like
Code: [Select]
d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; were identified by frankie as causing some access violations in the PrjZipWSDirMz add-in so I'll fix those first and see where to go from there.
« Last Edit: October 22, 2024, 11:46:51 AM by John Z »

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #5 on: October 22, 2024, 12:43:10 PM »
Passed the access crash!

changed
Code: [Select]
        if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
                   d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
into
Code: [Select]
        if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
         {
             int appo = TDEFL_LZ_DICT_SIZE + dst_pos;
              d->m_dict[appo] = c;
          }

Now no access violation crash  :)

Now 'only' a couple 100 errors
Code: [Select]
fatal error #2210: More than 100 errors, please improve yourself. and
an equal number of warnings..... :(  But I've not set the correct defines yet . . .progress though.

John Z

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #6 on: October 22, 2024, 02:43:18 PM »
It is working - compiles w/o error and within the program using it it creates the zip file with my 5 files included.
Could be cleaner as there are a lot of warnings just like the 1.19 version.

While the ZIP is usable there seems to be some subtle difference to trace down.  7z opens and displays ok, but seems something different within 1 file compared to 1.19.  Maybe a file length issue or padding as one of the 5 files in the new zip shows to be 1 byte shorter  - this causes (I think) Libreoffice to say the archive is corrupt, but it easily fixes it and all data is there. 

In any case it is close to working - - - x64 and w/o _POSIX_C_SOURCE (at least so far)

John Z
« Last Edit: October 22, 2024, 03:33:45 PM by John Z »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: miniz 3.0.2
« Reply #7 on: October 22, 2024, 05:54:41 PM »
richgel999's miniz updates frequently and perhaps better for Pelles C
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #8 on: October 22, 2024, 09:55:31 PM »
It is his but with an additional wrapper to make it easier to use.  :)

https://github.com/kuba--/zip
"A portable (OSX/Linux/Windows/Android/iOS), simple zip library written in C"
"This is done by hacking awesome miniz library and layering functions on top of the miniz v3.0.2 API."


John Z

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: miniz 3.0.2
« Reply #9 on: October 22, 2024, 10:29:07 PM »
Hi Timo,

Thanks for your suggestion. Using Msys2, I can compile richgel999's miniz code :

Code: [Select]
user@computer MINGW64 ~
# gcc -c miniz.c -o miniz.o

user@computer MINGW64 ~
# gcc example3.c miniz.o -o example3.exe

user@computer MINGW64 ~
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #10 on: October 22, 2024, 11:31:36 PM »
Hi Vortex,

Glad you have Msys2 working, I have not tried it yet.

If possible using your Msys2 compile can you ZIP the attached file and re-post?  It would be a big help to see if the 3.0.2 itself has an issue or if the wrapper around it has an issue. Using the wrapper version the packed file is 311 bytes but using my older 1.19 version it is 312 bytes.  With the missing 1 byte LibreOffice indicates the file is corrupt.  However it repairs it easily, and if I open the file and compare to the original it is identical so the issue is not the source but the compression/packing.  Interestingly only 1 file out of the five in the zip has the issue, so I'm think it may be a padding problem.

If possible - if not I appreciate your input too.

Thanks,
John Z

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: miniz 3.0.2
« Reply #11 on: October 22, 2024, 11:47:38 PM »
Hi John,

Here is the attached file :

Code: [Select]
# ./example3.exe c meta.xml meta.zip
miniz.c version: 11.0.2
Mode: c, Level: 9
Input File: "meta.xml"
Output File: "meta.zip"
Input file size: 642
Total input bytes: 642
Total output bytes: 317
Success.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 860
Re: miniz 3.0.2
« Reply #12 on: October 23, 2024, 12:04:38 AM »
Thanks very much Vortex!  Appreciate the help.

Wow this is even a different size too.

I'll check it out and see how LibreOffice likes it.

Thanks again!

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: miniz 3.0.2
« Reply #13 on: October 23, 2024, 06:41:20 AM »
example3.c with modified richgel999's miniz code

test_meta_xml is kuba zip version
32-bit version miss first char from filename  :(
« Last Edit: October 23, 2024, 08:11:15 AM by TimoVJL »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: miniz 3.0.2
« Reply #14 on: October 23, 2024, 11:05:30 AM »
Hi Timo,

Your example3 built and mine are producing the same zip file, no problem. As you said, test_meta_xml.exe is omitting the first character of the filename.
 
Code it... That's all...