0
votes

Good day!

Sometimes it happens that some part of the file in the Office Open XML format (docx, pptx, xslx) beats. It is known that these files are in fact the ZIP-files (possibly with a special compression algorithm?).

Is there any library (preferably with an example in C/C ++), which can check (not unpack) the integrity of the ZIP-file (check the CRC checksum of the archive contents)?

1
Welcome to stackoverflow. this is a Q&A site where you need to show whatever you have already tried yourself before people can help you. Please take a look at this : stackoverflow.com/help/how-to-askAnkur Aggarwal
@AnkurAggarwal Please vote to close this as a library request.Jonathan Mee

1 Answers

0
votes

I have used miniz:

BOOL isZipCorrect(const char *pFilename) {
  int ci;
  void *p;
  size_t uncomp_size;
  mz_bool status;
  mz_zip_archive zip_archive;
  // open the archive.
  memset(&zip_archive, 0, sizeof(zip_archive));
  status = mz_zip_reader_init_file(&zip_archive, pFilename, 0);
  if (!status) {
      return FALSE;
  }

  // go throw all files
  for (ci = 0; ci < (int)mz_zip_reader_get_num_files(&zip_archive); ci++) {
    // get information about each file in the archive
    mz_zip_archive_file_stat file_stat;
    if (!mz_zip_reader_file_stat(&zip_archive, ci, &file_stat))
    {
      mz_zip_reader_end(&zip_archive);
      return FALSE;
    }

    // try to extract this file
    p = mz_zip_reader_extract_file_to_heap(&zip_archive, file_stat.m_filename, &uncomp_size, 0);
    if (!p)
    {
      mz_zip_reader_end(&zip_archive);
      return FALSE;
    }

    // we're done.
    mz_free(p);
  }

  // close the archive, freeing any resources it was using
  mz_zip_reader_end(&zip_archive);

  // return ok state
  return TRUE;
}