Browse code

Modify unrar read_tables to treat "repeat previous code" at first position as error

Anthony Chan authored on 2018/02/24 08:11:18
Showing 2 changed files
... ...
@@ -470,9 +470,12 @@ static int read_tables(int fd, unpack_data_t *unpack_data)
470 470
 				n = (rar_getbits(unpack_data) >> 9) + 11;
471 471
 				rar_addbits(unpack_data, 7);
472 472
 			}
473
+			if (i == 0) {
474
+				rar_dbgmsg("We cannot have repeat previous code at the first position");
475
+				return FALSE;
476
+			}
473 477
 			while (n-- > 0 && i < table_size) {
474
-				if (i>0)
475
-					table[i] = table[i-1];
478
+				table[i] = table[i-1];
476 479
 				i++;
477 480
 			}
478 481
 		} else {
... ...
@@ -116,9 +116,12 @@ static int read_tables20(int fd, unpack_data_t *unpack_data)
116 116
 		} else if (number == 16) {
117 117
 			n = (rar_getbits(unpack_data) >> 14) + 3;
118 118
 			rar_addbits(unpack_data, 2);
119
+			if (i == 0) {
120
+				/* We cannot have "repeat previous" code at the first position */
121
+				return FALSE;
122
+			}
119 123
 			while ((n-- > 0) && (i < table_size)) {
120
-				if (i>0)
121
-					table[i] = table[i-1];
124
+				table[i] = table[i-1];
122 125
 				i++;
123 126
 			}
124 127
 		} else {