MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / validate_header

Method validate_header

external/basisu/transcoder/basisu_transcoder.cpp:9857–9928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9855 }
9856
9857 bool basisu_transcoder::validate_header(const void* pData, uint32_t data_size) const
9858 {
9859 if (data_size <= sizeof(basis_file_header))
9860 {
9861 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: input source buffer is too small\n");
9862 return false;
9863 }
9864
9865 const basis_file_header* pHeader = reinterpret_cast<const basis_file_header*>(pData);
9866
9867 if ((pHeader->m_sig != basis_file_header::cBASISSigValue) || (pHeader->m_ver != BASISD_SUPPORTED_BASIS_VERSION) || (pHeader->m_header_size != sizeof(basis_file_header)))
9868 {
9869 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: header has an invalid signature, or file version is unsupported\n");
9870 return false;
9871 }
9872
9873 uint32_t expected_file_size = sizeof(basis_file_header) + pHeader->m_data_size;
9874 if (data_size < expected_file_size)
9875 {
9876 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: input source buffer is too small, or header is corrupted\n");
9877 return false;
9878 }
9879
9880 if ((!pHeader->m_total_images) || (!pHeader->m_total_slices))
9881 {
9882 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: invalid basis file (total images or slices are 0)\n");
9883 return false;
9884 }
9885
9886 if (pHeader->m_total_images > pHeader->m_total_slices)
9887 {
9888 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: invalid basis file (too many images)\n");
9889 return false;
9890 }
9891
9892 if (pHeader->m_tex_format == (int)basis_tex_format::cETC1S)
9893 {
9894 if (pHeader->m_flags & cBASISHeaderFlagHasAlphaSlices)
9895 {
9896 if (pHeader->m_total_slices & 1)
9897 {
9898 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: invalid alpha .basis file\n");
9899 return false;
9900 }
9901 }
9902
9903 // This flag dates back to pre-Basis Universal, when .basis supported full ETC1 too.
9904 if ((pHeader->m_flags & cBASISHeaderFlagETC1S) == 0)
9905 {
9906 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: Invalid .basis file (ETC1S check)\n");
9907 return false;
9908 }
9909 }
9910 else
9911 {
9912 if ((pHeader->m_flags & cBASISHeaderFlagETC1S) != 0)
9913 {
9914 BASISU_DEVEL_ERROR("basisu_transcoder::get_total_images: Invalid .basis file (ETC1S check)\n");

Callers 6

openMethod · 0.80
GetThumbnailMethod · 0.80
mainFunction · 0.80
uploadFunction · 0.80
basis_fileMethod · 0.80
basis_openFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected