Load a description packet from a specified file
| 80 | |
| 81 | // Load a description packet from a specified file |
| 82 | bool DescriptionPacket::Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header) |
| 83 | { |
| 84 | // Is the packet big enough |
| 85 | if (header.length <= sizeof(FILEDESCRIPTIONPACKET)) |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // Is the packet too large (what is the longest permissible filename) |
| 91 | if (header.length - sizeof(FILEDESCRIPTIONPACKET) > 100000) |
| 92 | { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // Allocate the packet (with a little extra so we will have NULLs after the filename) |
| 97 | FILEDESCRIPTIONPACKET *packet = (FILEDESCRIPTIONPACKET *)AllocatePacket((size_t)header.length, 4); |
| 98 | |
| 99 | packet->header = header; |
| 100 | |
| 101 | // Read the rest of the packet from disk |
| 102 | if (!diskfile->Read(offset + sizeof(PACKET_HEADER), |
| 103 | &packet->fileid, |
| 104 | (size_t)packet->header.length - sizeof(PACKET_HEADER))) |
| 105 | return false; |
| 106 | |
| 107 | // Are the file and 16k hashes consistent |
| 108 | if (packet->length <= 16384 && packet->hash16k != packet->hashfull) |
| 109 | { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | // Returns the URL-style encoding of a character: |