MCPcopy Create free account
hub / github.com/OSSystems/EasySplash / scan_central_directory

Method scan_central_directory

src/zip_archive.cpp:201–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199
200
201void zip_archive::scan_central_directory(std::uint16_t const p_num_entries, std::uint32_t const p_central_dir_size, std::uint32_t const p_central_dir_pos)
202{
203 m_input.seekg(p_central_dir_pos, std::ios::beg);
204
205 for (std::uint16_t i = 0; i < p_num_entries; ++i)
206 {
207 entry new_entry;
208 std::uint16_t fn_length, extra_field_length, file_comment_length;
209
210 m_input.seekg(4 + 3*2, std::ios::cur); // skipping signature, version, required version, bit flag
211 read_binary(m_input, new_entry.m_compression_method);
212 m_input.seekg(2*2, std::ios::cur); // skipping last mod file time & date
213 read_binary(m_input, new_entry.m_CRC32_checksum);
214 read_binary(m_input, new_entry.m_compressed_size);
215 read_binary(m_input, new_entry.m_uncompressed_size);
216 read_binary(m_input, fn_length);
217 read_binary(m_input, extra_field_length);
218 read_binary(m_input, file_comment_length);
219 m_input.seekg(2*2 + 4, std::ios::cur); // skipping disk nr. start, internal & external file attributes
220 read_binary(m_input, new_entry.m_offset_to_local_header);
221
222 // copy the filename
223 new_entry.m_filename.resize(fn_length);
224 m_input.read(&(new_entry.m_filename[0]), new_entry.m_filename.size());
225 new_entry.m_filename = normalize_path(new_entry.m_filename);
226
227 // skip extra field & file comment so we are at the next file header in the central directory
228 m_input.seekg(extra_field_length + file_comment_length, std::ios::cur);
229
230 // check compression method
231 // checking here, to ensure filename, comments etc have been read/skipped
232 // and the input position is at the right place for reading the next header
233 if ((new_entry.m_compression_method != 0) && (new_entry.m_compression_method != 8))
234 {
235 LOG_MSG(warning, "zip entry \"" << new_entry.m_filename << "\" uses unsupported compression method " << new_entry.m_compression_method << " - skipping this entry");
236 continue;
237 }
238
239 // the offset is computed on-demand; 0 means "not computed yet"
240 new_entry.m_offset_to_data = 0;
241
242 m_entries[new_entry.m_filename] = new_entry;
243
244 // check if we are outside of the bounds of the central directory
245 assert((std::uint32_t(m_input.tellg()) - p_central_dir_pos) <= p_central_dir_size);
246 }
247}
248
249
250std::streamoff zip_archive::find_end_of_central_directory()

Callers

nothing calls this directly

Calls 1

normalize_pathFunction · 0.85

Tested by

no test coverage detected