Exemple #1
0
static bool verifyZip(const char *path) {
	QList<char *> entryList;
	bool found_duplicate = false;
	bool master_key_bug = false;
	bool bad_zip = false;

	do {
		unzFile file = unzOpen(path);
		if (file == NULL) {
			DBG("unzOpen failed!\n");
			bad_zip = true;
			break;
		}

		unz_global_info global_info;
		unz_file_info file_info;

		char entry[512];
		int n = -1;

		int r = unzGetGlobalInfo(file, &global_info);
		for (int i = 0; i < global_info.number_entry; i++) {
			if ((r = unzGetCurrentFileInfo(file, &file_info, entry,
					sizeof(entry), NULL, 0, NULL, 0)) != UNZ_OK) {
				DBG("unzGetCurrentFileInfo error\n");
				bad_zip = true;
				break;
			}

			for (int j = 0; j < entryList.size(); j++) {
				if (strcmp(entryList[j], entry) == 0) {
					DBG("found duplicate entry '%s' !\n", entry);
					found_duplicate = true;
					break;
				}
			}

			if (!found_duplicate) {
				char *t = new char[sizeof(entry)];
				strcpy(t, entry);
				entryList.append(t);
			} else {
				break;
			}

			if (i < global_info.number_entry - 1) {
				if ((r = unzGoToNextFile(file)) != UNZ_OK) {
					DBG("unzGoToNextFile error\n");
					bad_zip = true;
					break;
				}
			}
		}
		master_key_bug = unzHasMasterKeyBug(file) != 0;
		unzClose(file);
	} while (0);

	while (!entryList.isEmpty()) {
		delete[] entryList.takeAtFirst();
	}

	bool ret = !bad_zip && !found_duplicate && !master_key_bug;
	DBG("verifyZip ret = %d\n", ret);
	return ret;
}