make-errors.js (15063B)
1 // make-errors.js - Create C error enums, codes and strings for use in pure.h. 2 3 var Node = { 4 fs: require('fs') 5 }; 6 7 var errors = { 8 PURE_E_OK: "file is pure", 9 PURE_E_SIZE_MAX: "exceeded 64 GB limit", 10 PURE_E_MALLOC: "insufficient memory", 11 PURE_E_STRING_NOT_FOUND: "string not found", 12 PURE_E_UINT64_OVERFLOW: "uint64_t overflow", 13 PURE_E_ZIP_BOMB_ARCHIVES: "zip bomb: too many archives", 14 PURE_E_ZIP_BOMB_DEPTH: "zip bomb: too much recursion", 15 PURE_E_ZIP_BOMB_FIFIELD: "zip bomb: local file header overlap (see research by David Fifield)", 16 PURE_E_ZIP_BOMB_FILES: "zip bomb: too many files", 17 PURE_E_ZIP_BOMB_RATIO: "zip bomb: dangerous compression ratio and uncompressed size", 18 PURE_E_ZIP_BOMB_INFLATE_COMPRESSED_OVERFLOW: "zip bomb: compressed data is larger than compressed size (overflow)", 19 PURE_E_ZIP_BOMB_INFLATE_UNCOMPRESSED_OVERFLOW: "zip bomb: uncompressed data is larger than uncompressed size (overflow)", 20 PURE_E_ZIP_TOO_SMALL: "zip file too small (minimum size is 22 bytes)", 21 PURE_E_ZIP_SIZE_4GB: "unsupported: zip file exceeds 4 GB limit (ZIP64)", 22 PURE_E_ZIP_RAR: "not a zip file (malicious rar)", 23 PURE_E_ZIP_TAR: "not a zip file (malicious tar)", 24 PURE_E_ZIP_XAR: "not a zip file (malicious xar)", 25 PURE_E_ZIP_SIGNATURE: "not a zip file (bad signature)", 26 PURE_E_ZIP_EOCDR_NOT_FOUND: "end of central directory record: not found", 27 PURE_E_ZIP_EOCDR_OVERFLOW: "end of central directory record: overflow", 28 PURE_E_ZIP_EOCDR_COMMENT_OVERFLOW: "end of central directory record: comment overflow", 29 PURE_E_ZIP_EOCDR_SIGNATURE: "end of central directory record: bad signature", 30 PURE_E_ZIP_EOCDR_RECORDS: "end of central directory record: cd_disk_records != cd_records", 31 PURE_E_ZIP_EOCDR_SIZE_OVERFLOW: "end of central directory record: cd_size too small for number of cd_records", 32 PURE_E_ZIP_EOCDR_SIZE_UNDERFLOW: "end of central directory record: cd_size > 0 but cd_records == 0", 33 PURE_E_ZIP_MULTIPLE_DISKS: "unsupported: multiple disks", 34 PURE_E_ZIP_APPENDED_DATA_ZEROED: "zip file has appended data (zeroed)", 35 PURE_E_ZIP_APPENDED_DATA_BUFFER_BLEED: "zip file has appended data (buffer bleed)", 36 PURE_E_ZIP_PREPENDED_DATA: "zip file has prepended data", 37 PURE_E_ZIP_PREPENDED_DATA_ZEROED: "zip file has prepended data (zeroed)", 38 PURE_E_ZIP_PREPENDED_DATA_BUFFER_BLEED: "zip file has prepended data (buffer bleed)", 39 PURE_E_ZIP_CDH_OVERFLOW: "central directory header: overflow", 40 PURE_E_ZIP_CDH_SIGNATURE: "central directory header: bad signature", 41 PURE_E_ZIP_CDH_RELATIVE_OFFSET_OVERFLOW: "central directory header: relative offset overflow", 42 PURE_E_ZIP_CDH_RELATIVE_OFFSET_OVERLAP: "central directory header: relative offset overlaps central directory", 43 PURE_E_ZIP_CDH_FILE_NAME_OVERFLOW: "central directory header: file name overflow", 44 PURE_E_ZIP_CDH_EXTRA_FIELD_OVERFLOW: "central directory header: extra field overflow", 45 PURE_E_ZIP_CDH_FILE_COMMENT_OVERFLOW: "central directory header: file comment overflow", 46 PURE_E_ZIP_LFH_OVERFLOW: "local file header: overflow", 47 PURE_E_ZIP_LFH_SIGNATURE: "local file header: bad signature", 48 PURE_E_ZIP_LFH_FILE_NAME_OVERFLOW: "local file header: file name overflow", 49 PURE_E_ZIP_LFH_EXTRA_FIELD_OVERFLOW: "local file header: extra field overflow", 50 PURE_E_ZIP_LFH_UNDERFLOW_ZEROED: "local file header: gap (zeroed)", 51 PURE_E_ZIP_LFH_UNDERFLOW_BUFFER_BLEED: "local file header: gap (buffer bleed)", 52 PURE_E_ZIP_LFH_DATA_OVERFLOW: "local file header: data overflow", 53 PURE_E_ZIP_DDR_OVERFLOW: "data descriptor record: overflow", 54 PURE_E_ZIP_LF_OVERFLOW: "zip file has overlap between last local file and central directory", 55 PURE_E_ZIP_LF_UNDERFLOW_ZEROED: "zip file has gap between last local file and central directory (zeroed)", 56 PURE_E_ZIP_LF_UNDERFLOW_BUFFER_BLEED: "zip file has gap between last local file and central directory (buffer bleed)", 57 PURE_E_ZIP_CD_OVERFLOW: "central directory: overflow", 58 PURE_E_ZIP_CD_UNDERFLOW_ZEROED: "central directory: underflow (zeroed)", 59 PURE_E_ZIP_CD_UNDERFLOW_BUFFER_BLEED: "central directory: underflow (buffer bleed)", 60 PURE_E_ZIP_CD_EOCDR_OVERFLOW: "central directory overlaps end of central directory record", 61 PURE_E_ZIP_CD_EOCDR_UNDERFLOW_ZEROED: "zip file has gap between central directory and end of central directory record (zeroed)", 62 PURE_E_ZIP_CD_EOCDR_UNDERFLOW_BUFFER_BLEED: "zip file has gap between central directory and end of central directory record (buffer bleed)", 63 PURE_E_ZIP_DIFF_LFH_GENERAL_PURPOSE_BIT_FLAG: "local file header diverges from central directory header: general purpose bit flag", 64 PURE_E_ZIP_DIFF_LFH_COMPRESSION_METHOD: "local file header diverges from central directory header: compression method", 65 PURE_E_ZIP_DIFF_LFH_LAST_MOD_FILE_TIME: "local file header diverges from central directory header: last mod file time", 66 PURE_E_ZIP_DIFF_LFH_LAST_MOD_FILE_DATE: "local file header diverges from central directory header: last mod file date", 67 PURE_E_ZIP_DIFF_LFH_CRC32: "local file header diverges from central directory header: crc32", 68 PURE_E_ZIP_DIFF_LFH_COMPRESSED_SIZE: "local file header diverges from central directory header: compressed size", 69 PURE_E_ZIP_DIFF_LFH_UNCOMPRESSED_SIZE: "local file header diverges from central directory header: uncompressed size", 70 PURE_E_ZIP_DIFF_LFH_FILE_NAME_LENGTH: "local file header diverges from central directory header: file name length", 71 PURE_E_ZIP_DIFF_LFH_FILE_NAME: "local file header diverges from central directory header: file name", 72 PURE_E_ZIP_DIFF_LFH_DDR_CRC32: "local file header diverges from data descriptor record: crc32", 73 PURE_E_ZIP_DIFF_LFH_DDR_COMPRESSED_SIZE: "local file header diverges from data descriptor record: compressed size", 74 PURE_E_ZIP_DIFF_LFH_DDR_UNCOMPRESSED_SIZE: "local file header diverges from data descriptor record: uncompressed size", 75 PURE_E_ZIP_DIFF_DDR_CRC32: "data descriptor record diverges from central directory header: crc32", 76 PURE_E_ZIP_DIFF_DDR_COMPRESSED_SIZE: "data descriptor record diverges from central directory header: compressed size", 77 PURE_E_ZIP_DIFF_DDR_UNCOMPRESSED_SIZE: "data descriptor record diverges from central directory header: uncompressed size", 78 PURE_E_ZIP_FLAG_OVERFLOW: "general purpose bit flag: 16-bit overflow", 79 PURE_E_ZIP_FLAG_TRADITIONAL_ENCRYPTION: "unsupported: traditional encryption", 80 PURE_E_ZIP_FLAG_ENHANCED_DEFLATE: "unsupported: enhanced deflate", 81 PURE_E_ZIP_FLAG_COMPRESSED_PATCHED_DATA: "unsupported: compressed patched data", 82 PURE_E_ZIP_FLAG_STRONG_ENCRYPTION: "unsupported: strong encryption", 83 PURE_E_ZIP_FLAG_UNUSED_BIT_7: "unsupported: unused flag (bit 7)", 84 PURE_E_ZIP_FLAG_UNUSED_BIT_8: "unsupported: unused flag (bit 8)", 85 PURE_E_ZIP_FLAG_UNUSED_BIT_9: "unsupported: unused flag (bit 9)", 86 PURE_E_ZIP_FLAG_UNUSED_BIT_10: "unsupported: unused flag (bit 10)", 87 PURE_E_ZIP_FLAG_ENHANCED_COMPRESSION: "unsupported: enhanced compression", 88 PURE_E_ZIP_FLAG_MASKED_LOCAL_HEADERS: "unsupported: masked local headers", 89 PURE_E_ZIP_FLAG_RESERVED_BIT_14: "unsupported: reserved flag (bit 14)", 90 PURE_E_ZIP_FLAG_RESERVED_BIT_15: "unsupported: reserved flag (bit 15)", 91 PURE_E_ZIP_COMPRESSION_METHOD_DANGEROUS: "compression method: exceeds 999 (CVE-2016-9844)", 92 PURE_E_ZIP_COMPRESSION_METHOD_ENCRYPTED: "compression method: encrypted", 93 PURE_E_ZIP_COMPRESSION_METHOD_UNSUPPORTED: "compression method: must be 0 or 8", 94 PURE_E_ZIP_STORED_COMPRESSION_SIZE_MISMATCH: "file stored with no compression has mismatching compressed and uncompressed sizes", 95 PURE_E_ZIP_DANGEROUS_NEGATIVE_COMPRESSION_RATIO: "dangerous negative compression ratio (CVE-2018-18384)", 96 PURE_E_ZIP_TIME_OVERFLOW: "time: 16-bit overflow", 97 PURE_E_ZIP_TIME_HOUR_OVERFLOW: "time: ms-dos hour: overflow", 98 PURE_E_ZIP_TIME_MINUTE_OVERFLOW: "time: ms-dos minute: overflow", 99 PURE_E_ZIP_TIME_SECOND_OVERFLOW: "time: ms-dos second: overflow", 100 PURE_E_ZIP_DATE_OVERFLOW: "date: 16-bit overflow", 101 PURE_E_ZIP_DATE_YEAR_OVERFLOW: "date: ms-dos year: overflow", 102 PURE_E_ZIP_DATE_MONTH_OVERFLOW: "date: ms-dos month: overflow", 103 PURE_E_ZIP_DATE_DAY_OVERFLOW: "date: ms-dos day: overflow", 104 PURE_E_ZIP_FILE_NAME_LENGTH: "file name exceeds 4096 bytes (CVE-2018-1000035)", 105 PURE_E_ZIP_FILE_NAME_CONTROL_CHARACTERS: "file name contains control characters (CVE-2003-0282)", 106 PURE_E_ZIP_FILE_NAME_TRAVERSAL_DRIVE_PATH: "directory traversal (via file name drive path)", 107 PURE_E_ZIP_FILE_NAME_TRAVERSAL_RELATIVE_PATH: "directory traversal (via file name relative path)", 108 PURE_E_ZIP_FILE_NAME_TRAVERSAL_DOUBLE_DOTS: "directory traversal (via file name double dots)", 109 PURE_E_ZIP_FILE_NAME_COMPONENT_OVERFLOW: "file name path component exceeds 255 bytes", 110 PURE_E_ZIP_FILE_NAME_BACKSLASH: "file name contains backslash", 111 PURE_E_ZIP_EXTRA_FIELD_MAX: "extra field length exceeds maximum", 112 PURE_E_ZIP_EXTRA_FIELD_MIN: "extra field length must be 0 or at least 4 bytes", 113 PURE_E_ZIP_EXTRA_FIELD_ATTRIBUTE_OVERFLOW: "extra field: attribute overflow", 114 PURE_E_ZIP_EXTRA_FIELD_OVERFLOW: "extra field: overflow", 115 PURE_E_ZIP_EXTRA_FIELD_UNDERFLOW_ZEROED: "extra field: underflow (zeroed)", 116 PURE_E_ZIP_EXTRA_FIELD_UNDERFLOW_BUFFER_BLEED: "extra field: underflow (buffer bleed)", 117 PURE_E_ZIP_EXTRA_FIELD_UNICODE_PATH_OVERFLOW: "extra field: unicode path overflow", 118 PURE_E_ZIP_EXTRA_FIELD_UNICODE_PATH_VERSION: "extra field: unicode path has an invalid version", 119 PURE_E_ZIP_EXTRA_FIELD_UNICODE_PATH_DIFF: "extra field: unicode path diverges from file name", 120 PURE_E_ZIP_UNIX_MODE_OVERFLOW: "unix mode: overflow", 121 PURE_E_ZIP_UNIX_MODE_BLOCK_DEVICE: "unix mode: dangerous type (block device)", 122 PURE_E_ZIP_UNIX_MODE_CHARACTER_DEVICE: "unix mode: dangerous type (character device)", 123 PURE_E_ZIP_UNIX_MODE_FIFO: "unix mode: dangerous type (fifo)", 124 PURE_E_ZIP_UNIX_MODE_SOCKET: "unix mode: dangerous type (socket)", 125 PURE_E_ZIP_UNIX_MODE_PERMISSIONS_STICKY: "unix mode: dangerous permissions (sticky)", 126 PURE_E_ZIP_UNIX_MODE_PERMISSIONS_SETGID: "unix mode: dangerous permissions (setgid)", 127 PURE_E_ZIP_UNIX_MODE_PERMISSIONS_SETUID: "unix mode: dangerous permissions (setuid)", 128 PURE_E_ZIP_DIRECTORY_COMPRESSED: "directory: non-zero compressed size", 129 PURE_E_ZIP_DIRECTORY_UNCOMPRESSED: "directory: non-zero uncompressed size", 130 PURE_E_ZIP_SYMLINK_COMPRESSED: "unsupported: compressed symlink", 131 PURE_E_ZIP_SYMLINK_LENGTH: "symlink exceeds 4096 bytes (CVE-2018-1000035)", 132 PURE_E_ZIP_SYMLINK_CONTROL_CHARACTERS: "symlink contains control characters (CVE-2003-0282)", 133 PURE_E_ZIP_SYMLINK_TRAVERSAL_DRIVE_PATH: "directory traversal (via symlink drive path)", 134 PURE_E_ZIP_SYMLINK_TRAVERSAL_RELATIVE_PATH: "directory traversal (via symlink relative path)", 135 PURE_E_ZIP_SYMLINK_TRAVERSAL_DOUBLE_DOTS: "directory traversal (via symlink double dots)", 136 PURE_E_ZIP_SYMLINK_COMPONENT_OVERFLOW: "symlink path component exceeds 255 bytes", 137 PURE_E_ZIP_STRING_MAX: "string exceeds reasonable limit (PURE_ZIP_STRING_MAX)", 138 PURE_E_ZIP_STRING_NULL_BYTE: "string contains a dangerous null byte", 139 PURE_E_ZIP_INFLATE: "zip file could not be uncompressed", 140 PURE_E_ZIP_INFLATE_DICTIONARY: "zip file could not be uncompressed (dictionary error)", 141 PURE_E_ZIP_INFLATE_STREAM: "zip file could not be uncompressed (stream error)", 142 PURE_E_ZIP_INFLATE_DATA: "zip file could not be uncompressed (data error)", 143 PURE_E_ZIP_INFLATE_MEMORY: "zip file could not be uncompressed (memory error)", 144 PURE_E_ZIP_INFLATE_COMPRESSED_UNDERFLOW: "compressed data is smaller than compressed size", 145 PURE_E_ZIP_INFLATE_UNCOMPRESSED_UNDERFLOW: "uncompressed data is smaller than uncompressed size", 146 PURE_E_ZIP_AD_NIHILO: "file has a zero uncompressed size but a non-zero compressed size or invalid compressed data (ad nihilo)", 147 PURE_E_ZIP_EX_NIHILO: "file has a zero compressed size but a non-zero uncompressed size (ex nihilo)", 148 PURE_E_ZIP_CRC32: "file is corrupt or has an invalid crc32 checksum", 149 PURE_E_ZIP_EOCDL_64_OVERFLOW: "zip64 end of central directory locator: overflow", 150 PURE_E_ZIP_EOCDL_64_SIGNATURE: "zip64 end of central directory locator: bad signature", 151 PURE_E_ZIP_EOCDL_64_NEGATIVE_OFFSET: "zip64 end of central directory locator: negative offset", 152 PURE_E_ZIP_EOCDL_64_DISK: "zip64 end of central directory locator: disk != 0", 153 PURE_E_ZIP_EOCDL_64_DISKS: "zip64 end of central directory locator: disks > 1", 154 PURE_E_ZIP_EOCDR_64_OVERFLOW: "zip64 end of central directory record: overflow", 155 PURE_E_ZIP_EOCDR_64_SIGNATURE: "zip64 end of central directory record: bad signature", 156 PURE_E_ZIP_EOCDR_EOCDL_64_OVERFLOW: "zip64 eocdr overlaps zip64 eocdl", 157 PURE_E_ZIP_EOCDR_EOCDL_64_UNDERFLOW_ZEROED: "gap between zip64 eocdr and zip64 eocdl (zeroed)", 158 PURE_E_ZIP_EOCDR_EOCDL_64_UNDERFLOW_BUFFER_BLEED: "gap between zip64 eocdr and zip64 eocdl (buffer bleed)", 159 PURE_E_ZIP_DIFF_EOCDR_DISK: "eocdr diverges from zip64 eocdr: disk", 160 PURE_E_ZIP_DIFF_EOCDR_CD_DISK: "eocdr diverges from zip64 eocdr: cd_disk", 161 PURE_E_ZIP_DIFF_EOCDR_CD_DISK_RECORDS: "eocdr diverges from zip64 eocdr: cd_disk_records", 162 PURE_E_ZIP_DIFF_EOCDR_CD_RECORDS: "eocdr diverges from zip64 eocdr: cd_records", 163 PURE_E_ZIP_DIFF_EOCDR_CD_SIZE: "eocdr diverges from zip64 eocdr: cd_size", 164 PURE_E_ZIP_DIFF_EOCDR_CD_OFFSET: "eocdr diverges from zip64 eocdr: cd_offset", 165 PURE_E_ZIP_EIEF_64_COMPRESSED_SIZE: "zip64 extended information extra field: missing compressed_size", 166 PURE_E_ZIP_EIEF_64_DISK: "zip64 extended information extra field: missing disk", 167 PURE_E_ZIP_EIEF_64_RELATIVE_OFFSET: "zip64 extended information extra field: missing relative_offset", 168 PURE_E_ZIP_EIEF_64_UNCOMPRESSED_SIZE: "zip64 extended information extra field: missing uncompressed_size", 169 PURE_E_ZIP_EIEF_64_UNDERFLOW_ZEROED: "zip64 extended information extra field: appended data (zeroed)", 170 PURE_E_ZIP_EIEF_64_UNDERFLOW_BUFFER_BLEED: "zip64 extended information extra field: appended data (buffer bleed)", 171 PURE_E_ZIP_EIEF_64_LFH: "zip64 extended information extra field: local file header must include both uncompressed_size and compressed_size", 172 PURE_E_ZIP_DIRECTORY_HAS_NO_LFH: "a directory has no local file header" 173 }; 174 175 var lines = []; 176 177 function line(string) { 178 lines.push(string); 179 } 180 181 function enums() { 182 line('enum PURE_E {'); 183 for (var code in errors) line(' ' + code + ','); 184 line(' // Capture enum length for bounds checking by pure_error_string():'); 185 line(' PURE_E_ENUM_LENGTH'); 186 line('};'); 187 } 188 189 function codes() { 190 line(''); 191 line('const char* const PURE_E_CODES[] = {'); 192 var count = 0; 193 var length = Object.keys(errors).length; 194 for (var code in errors) { 195 line(' "' + code + '"' + (++count < length ? ',' : '')); 196 } 197 line('};'); 198 } 199 200 function strings() { 201 line(''); 202 line('const char* const PURE_E_STRINGS[] = {'); 203 var count = 0; 204 var length = Object.keys(errors).length; 205 for (var code in errors) { 206 line(' "' + errors[code] + '"' + (++count < length ? ',' : '')); 207 } 208 line('};'); 209 } 210 211 enums(); 212 codes(); 213 strings(); 214 215 Node.fs.writeFileSync('pure_errors.h', lines.join('\n'), 'utf-8');