MCPcopy Create free account
hub / github.com/Parchive/par2cmdline / Load

Method Load

src/mainpacket.cpp:82–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80// Load a main packet from a specified file
81
82bool MainPacket::Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header)
83{
84 // Is the packet large enough
85 if (header.length < sizeof(MAINPACKET))
86 {
87 return false;
88 }
89
90 // Is there a whole number of fileid values
91 if (0 < (header.length - sizeof(MAINPACKET)) % sizeof(MD5Hash))
92 {
93 return false;
94 }
95
96 // Is the packet too large
97 if (header.length > sizeof(MAINPACKET) + 32768 * sizeof(MD5Hash))
98 {
99 return false;
100 }
101
102 // Compute the total number of entries in the fileid array
103 totalfilecount = (u32)(((size_t)header.length - sizeof(MAINPACKET)) / sizeof(MD5Hash));
104
105 MAINPACKET *packet = (MAINPACKET *)AllocatePacket((size_t)header.length);
106
107 packet->header = header;
108
109 // Read the rest of the packet from disk
110 if (!diskfile->Read(offset + sizeof(PACKET_HEADER),
111 &packet->blocksize,
112 (size_t)packet->header.length - sizeof(PACKET_HEADER)))
113 return false;
114
115 // Does the packet have enough fileid values
116 recoverablefilecount = packet->recoverablefilecount;
117 if (recoverablefilecount > totalfilecount)
118 {
119 return false;
120 }
121
122 // Is the block size valid
123 blocksize = packet->blocksize;
124 if (blocksize == 0 || (blocksize & 3) != 0)
125 {
126 return false;
127 }
128
129 return true;
130}

Callers 6

LoadRecoveryPacketMethod · 0.45
LoadDescriptionPacketMethod · 0.45
LoadMainPacketMethod · 0.45
LoadCreatorPacketMethod · 0.45

Calls 1

ReadMethod · 0.80

Tested by

no test coverage detected