--- /dev/null
+#include "test.h"
+
+DEFINE_TEST(test_read_format_cab_skip_malformed)
+{
+ /* Reference to the malformed CAB file */
+ const char *refname = "test_read_format_cab_skip_malformed.cab";
+ struct archive *a;
+ struct archive_entry *ae;
+ void *buffer;
+ size_t buffersize;
+
+ /* Extract the reference file into the test sandbox */
+ extract_reference_file(refname);
+
+ /* Read the entire file into memory */
+ buffer = slurpfile(&buffersize, "%s", refname);
+ assert(buffer != NULL);
+
+ /* Initialize the archive reader */
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+
+ /* Read from memory (a prerequisite for triggering this specific bug) */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buffer, buffersize));
+
+ /* Simulate the parsing flow to trigger the implicit skip routine */
+ while (archive_read_next_header(a, &ae) == ARCHIVE_OK) {
+ const void *buff;
+ size_t size_read;
+ int64_t offset;
+ while (archive_read_data_block(a, &buff, &size_read, &offset) == ARCHIVE_OK) {
+ /* Consume data. This will fail quickly due to the malformed payload. */
+ }
+ }
+
+ /* Clean up. If the patch is effective, the program reaches here safely. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ free(buffer);
+}
\ No newline at end of file
--- /dev/null
+begin 664 test_read_format_cab_skip_malformed.cab
+M35-#1@````!!``"2DI*2DI(````````2Y``!``$``,2PW@``'P$``-(!```!
+M.]+2"0D)"0D)"0D)"0D)"0D)"0FRLK*R"0D)"0D)"0D)"0D)LK*RLK*RLK(`
+M``````````````````"RLK*RLK*RLK*RLK*RLK*RLK(*,```````````````
+M````LK*RX____[:RL@```````````````#`W,"]`````"G!P`````&UDL@HP
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````%!+`P0````!#`P,#`P,#`P,#`P,#```````````````__\```3_
+M``!(___H````````````````````````````````````````____________
+M____________________________________________________````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M@```````````````@`````$`````````````````````````````````````
+M````````````````````````````````````````````#`H,#````'H,#`P`
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````#__P``!/\``$C__^@```````````#_________________________
+M______________________________________\`````````````````````
+M`"\O+R\O+R\O+R\O+R\O+R\O+R\O+R\G+PHQ-C4P+U):22\P-S!,4EI)"@HO
+M=6YS970@<F$@("T@("!/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T\@(2`@("`@
+M+2`@("`@("`@(",@("`@("`@("L@("`@("`@("`@("`@("`@("`@("`@("`@
+M("`K('A,4EI)"@H*("`@("`@(```````````````````````````````````
+M```````````````````````````````````````````````````,]@P,#`H*
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````#__P``!/\``$C__^@`````
+M`%``````````````````````````````````________________________
+M________________________________________````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````@```````
+M````````@`````$`````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````#__P``!/\``$C__^@`
+M``````````#_________________________________________________
+M______________\`````````````````````````````````````````````
+M`````````````````````%!+`P0````!#`P,#`P,#`P,#`P,#```#`H,#```
+M`'H,````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````,#`SV``````````````````````P,
+M#`H*`/__```$_P``2/__Z````````````%#_________________________
+M______________________________________\`````````````````````
+M````````````````````````````````````````````+R\P23@*"DQ:3#`P
+M"DQ26DD*"DQ:+PH*,#`W,"\O,#<P+R\O+R\O+S!).`H*3%I,,"\P-S!,4EI)
+M"@I,6B\O"F)E9VEN-F%E<RUB-"`Q(%TP-#`P5T%20R\O25HX"DQ,,`I,4EI)
+M"@I,6B\O-S`W"DQ:3#`O,#<P3%):20H*3%HO+PIB96=I;BUB87-E-C0@-B`P
+M-#`P5T%20R\O25HX"DQ,,`I,4EI)"@I,6B\O-S`W,#<O+R]:4B\O+R\O"C!@
+M-S`W,#$*#8V-C8V-C8V-C8V-C8V-C8V-C5!+`P10"@`*"C`P-S`O+S`W,"\O
+M+R\O+R\P23@*"DQ:3#`O,#<P3%):20H*3%HO+PIB96=I;BUB87-E-C0@,2`P
+M-#`P5T%20R\O25HX"DQ,"DQ:3#`O,#<P3%):20H*3%HO+PIB96=I;BUB87-E
+M-C0@,2`P-#`P5T%20R\O25HV"DQ,,`I,4EI)"@I,6B\*"C`P-S`O+S`W,"\O
+M+R\O+R\P23@*"DQ:3#`O,#<P3%):20H*3%HO+PIB90``V/\M`?\-__\-_RO_
+M_?____\F__\+____B?\*)PH``')R<G)R<G)R<G+_____________________
+M____________________________________________________________
+M____________________________________________________________
+M____________________________________________________<G)R<G)R
+M<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)R<G)``!0`
+M`````````````````$#_____"`1W2"__0`#D$P`G_D3________NXEQ<7%QR
+M7#`P-S=<,#)<7%Q<7%Q<?%Q<7%Q<<EPP,#<W7#`R7%Q<7%Q<7%Q<,#)<7%Q<
+M7%Q<7')<,#`W-UPP,EQ<7%Q<7"L*=75,6B\O"F)E9VEN+6)A<V4V-"`V(#`T
+M,#!705)#+R])6C@*3"`Q(#`T,#!705)#+R])6C@*3$P*3%I,,"\P-S!,4EI)
+M"@I,6B\O"F)E9VEN+6)A<V4V-"`Q(#`T,#!705)#+R])6C@*3$PP"DQ26DD*
+M"DQ:+PH*,#`W,"\O,#<P+R\O+R\O+S!).`H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