| 2886 | } |
| 2887 | |
| 2888 | UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, const UINT32 dictionarySize, QByteArray & compressedData) |
| 2889 | { |
| 2890 | UINT8* compressed; |
| 2891 | |
| 2892 | switch (algorithm) { |
| 2893 | case COMPRESSION_ALGORITHM_NONE: |
| 2894 | { |
| 2895 | compressedData = data; |
| 2896 | return ERR_SUCCESS; |
| 2897 | } |
| 2898 | break; |
| 2899 | case COMPRESSION_ALGORITHM_EFI11: |
| 2900 | { |
| 2901 | // Try legacy function first |
| 2902 | UINT32 compressedSize = 0; |
| 2903 | if (EfiCompressLegacy(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL) |
| 2904 | return ERR_STANDARD_COMPRESSION_FAILED; |
| 2905 | compressed = new UINT8[compressedSize]; |
| 2906 | if (EfiCompressLegacy(data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) { |
| 2907 | delete[] compressed; |
| 2908 | return ERR_STANDARD_COMPRESSION_FAILED; |
| 2909 | } |
| 2910 | compressedData = QByteArray((const char*)compressed, compressedSize); |
| 2911 | |
| 2912 | // Check that compressed data can be decompressed normally |
| 2913 | QByteArray decompressed; |
| 2914 | if (decompress(compressedData, EFI_STANDARD_COMPRESSION, decompressed, NULL) == ERR_SUCCESS |
| 2915 | && decompressed == data) { |
| 2916 | delete[] compressed; |
| 2917 | return ERR_SUCCESS; |
| 2918 | } |
| 2919 | delete[] compressed; |
| 2920 | |
| 2921 | // Legacy function failed, use current one |
| 2922 | compressedSize = 0; |
| 2923 | if (EfiCompress(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL) |
| 2924 | return ERR_STANDARD_COMPRESSION_FAILED; |
| 2925 | compressed = new UINT8[compressedSize]; |
| 2926 | if (EfiCompress(data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) { |
| 2927 | delete[] compressed; |
| 2928 | return ERR_STANDARD_COMPRESSION_FAILED; |
| 2929 | } |
| 2930 | compressedData = QByteArray((const char*)compressed, compressedSize); |
| 2931 | |
| 2932 | // New functions will be trusted here, because another check will reduce performance |
| 2933 | delete[] compressed; |
| 2934 | return ERR_SUCCESS; |
| 2935 | } |
| 2936 | break; |
| 2937 | case COMPRESSION_ALGORITHM_TIANO: |
| 2938 | { |
| 2939 | // Try legacy function first |
| 2940 | UINT32 compressedSize = 0; |
| 2941 | if (TianoCompressLegacy(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL) |
| 2942 | return ERR_STANDARD_COMPRESSION_FAILED; |
| 2943 | compressed = new UINT8[compressedSize]; |
| 2944 | if (TianoCompressLegacy(data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) { |
| 2945 | delete[] compressed; |
nothing calls this directly
no test coverage detected