aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/stream_flags_common.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/stream_flags_common.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/liblzma/common/stream_flags_common.c b/src/liblzma/common/stream_flags_common.c
index c44b3ff2..aaa9fe02 100644
--- a/src/liblzma/common/stream_flags_common.c
+++ b/src/liblzma/common/stream_flags_common.c
@@ -24,17 +24,31 @@ const uint8_t lzma_header_magic[6] = { 0xFF, 0x4C, 0x5A, 0x4D, 0x41, 0x00 };
const uint8_t lzma_footer_magic[2] = { 0x59, 0x5A };
-extern LZMA_API lzma_bool
-lzma_stream_flags_equal(const lzma_stream_flags *a, const lzma_stream_flags *b)
+extern LZMA_API lzma_ret
+lzma_stream_flags_compare(
+ const lzma_stream_flags *a, const lzma_stream_flags *b)
{
+ // We can compare only version 0 structures.
+ if (a->version != 0 || b->version != 0)
+ return LZMA_HEADER_ERROR;
+
+ // Check type
+ if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX
+ || (unsigned int)(b->check) > LZMA_CHECK_ID_MAX)
+ return LZMA_PROG_ERROR;
+
if (a->check != b->check)
- return false;
+ return LZMA_DATA_ERROR;
// Backward Sizes are compared only if they are known in both.
if (a->backward_size != LZMA_VLI_VALUE_UNKNOWN
- && b->backward_size != LZMA_VLI_VALUE_UNKNOWN
- && a->backward_size != b->backward_size)
- return false;
+ && b->backward_size != LZMA_VLI_VALUE_UNKNOWN) {
+ if (!is_backward_size_valid(a) || !is_backward_size_valid(b))
+ return LZMA_PROG_ERROR;
+
+ if (a->backward_size != b->backward_size)
+ return LZMA_DATA_ERROR;
+ }
- return true;
+ return LZMA_OK;
}