| 1137 | } |
| 1138 | |
| 1139 | void |
| 1140 | ktxValidator::validateFile(const string& filename) |
| 1141 | { |
| 1142 | validationContext context; |
| 1143 | istream* isp; |
| 1144 | // These 2 need to be declared here so they stay around for the life |
| 1145 | // of this method. |
| 1146 | ifstream ifs; |
| 1147 | stringstream buffer; |
| 1148 | bool doBuffer; |
| 1149 | |
| 1150 | if (filename.compare("-") == 0) { |
| 1151 | #if defined(_WIN32) |
| 1152 | /* Set "stdin" to have binary mode */ |
| 1153 | (void)_setmode( _fileno( stdin ), _O_BINARY ); |
| 1154 | // Windows shells set the FILE_SYNCHRONOUS_IO_NONALERT option when |
| 1155 | // creating pipes. Cygwin since 3.4.x does the same thing, a change |
| 1156 | // which affects anything dependent on it, e.g. Git for Windows |
| 1157 | // (since 2.41.0) and MSYS2. When this option is set, cin.seekg(0) |
| 1158 | // erroneously returns success. Always buffer. |
| 1159 | doBuffer = true; |
| 1160 | #else |
| 1161 | // Can we seek in this cin? |
| 1162 | cin.seekg(0); |
| 1163 | doBuffer = cin.fail(); |
| 1164 | #endif |
| 1165 | if (doBuffer) { |
| 1166 | // Read entire file into a stringstream so we can seek. |
| 1167 | buffer << cin.rdbuf(); |
| 1168 | buffer.seekg(0, ios::beg); |
| 1169 | isp = &buffer; |
| 1170 | } else { |
| 1171 | isp = &cin; |
| 1172 | } |
| 1173 | } else { |
| 1174 | // MS's STL has `open` overloads that accept wchar_t* and wstring to |
| 1175 | // handle Window's Unicode file names. Unfortunately non-MS STL has |
| 1176 | // only wchar_t*. |
| 1177 | ifs.open(DecodeUTF8Path(filename).c_str(), |
| 1178 | ios_base::in | ios_base::binary); |
| 1179 | isp = &ifs; |
| 1180 | } |
| 1181 | |
| 1182 | logger.startFile(isp != &ifs ? "stdin" : filename); |
| 1183 | if (!isp->fail()) { |
| 1184 | try { |
| 1185 | context.init(isp); |
| 1186 | validateHeader(context); |
| 1187 | validateLevelIndex(context); |
| 1188 | // DFD is validated from within validateLevelIndex. |
| 1189 | validateKvd(context); |
| 1190 | if (context.header.supercompressionGlobalData.byteLength > 0) |
| 1191 | skipPadding(context, 8); |
| 1192 | validateSgd(context); |
| 1193 | skipPadding(context, context.requiredLevelAlignment()); |
| 1194 | validateDataSize(context); |
| 1195 | validateTranscode(context); |
| 1196 | } catch (fatal& e) { |
nothing calls this directly
no test coverage detected