diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 8c90bb6ab0fe464806e5da24905cc069277f45d0..14a2d23f49306428e471ff5ea9d5773072f18129 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -114,7 +114,7 @@ static int xan_huffman_decode(unsigned char *dest, int dest_len,
     while (val != 0x16) {
         unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
         if (idx >= 2 * byte)
-            return -1;
+            return AVERROR_INVALIDDATA;
         val = src[idx];
 
         if (val < 0x16) {