1717
1818#include "bsvmovie.h"
1919#include <retro_endianness.h>
20+ #include <stdint.h>
2021#include "../input_driver.h"
2122#include "../../retroarch.h"
2223#include "../../state_manager.h"
@@ -144,7 +145,8 @@ static bool bsv_movie_peek_frame_info(bsv_movie_t *movie, uint8_t *token, uint64
144145 if (intfstream_read (movie -> file , & (state_length ), sizeof (uint64_t )) != sizeof (uint64_t ))
145146 goto end ;
146147 state_length = swap_if_big64 (state_length );
147- ret = intfstream_seek (movie -> file , state_length , SEEK_CUR ) >= 0 ;
148+ if (intfstream_seek (movie -> file , state_length , SEEK_CUR ) < 0 )
149+ goto end ;
148150 }
149151 else if (tok == REPLAY_TOKEN_CHECKPOINT2_FRAME )
150152 {
@@ -156,7 +158,8 @@ static bool bsv_movie_peek_frame_info(bsv_movie_t *movie, uint8_t *token, uint64
156158 if (intfstream_read (movie -> file , & (state_length ), sizeof (uint32_t )) != sizeof (uint32_t ))
157159 goto end ;
158160 /* Seek past the state data */
159- ret = intfstream_seek (movie -> file , state_length , SEEK_CUR ) >= 0 ;
161+ if (intfstream_seek (movie -> file , state_length , SEEK_CUR ) < 0 )
162+ goto end ;
160163 }
161164 /* We are already at the end of the frame */
162165 else if (tok == REPLAY_TOKEN_REGULAR_FRAME ) { }
@@ -668,7 +671,7 @@ int64_t bsv_movie_write_checkpoint(bsv_movie_t *handle, uint8_t compression, uin
668671 uint8_t * swap ;
669672 size_t size_swap ;
670673 int64_t ret = -1 ;
671- uint32_t encoded_size = 0 , compressed_encoded_size = 0 , size_ = 0 ;
674+ uint32_t encoded_size = 0 , compressed_encoded_size , size_ = 0 ;
672675 uint8_t * encoded_data = NULL , * compressed_encoded_data = NULL ;
673676 bool owns_encoded = false, owns_compressed_encoded = false;
674677 retro_ctx_serialize_info_t serial_info ;
@@ -732,17 +735,17 @@ int64_t bsv_movie_write_checkpoint(bsv_movie_t *handle, uint8_t compression, uin
732735#ifdef HAVE_ZSTD
733736 case REPLAY_CHECKPOINT2_COMPRESSION_ZSTD :
734737 {
735- size_t compressed_encoded_size = ZSTD_compressBound (encoded_size );
736- compressed_encoded_data = (uint8_t * )calloc (compressed_encoded_size , sizeof (uint8_t ));
738+ size_t compressed_encoded_size_zstd = ZSTD_compressBound (encoded_size );
739+ compressed_encoded_data = (uint8_t * )calloc (compressed_encoded_size_zstd , sizeof (uint8_t ));
737740 owns_compressed_encoded = true;
738- compressed_encoded_size = ZSTD_compress (compressed_encoded_data , compressed_encoded_size , encoded_data , encoded_size , 3 );
739- if (ZSTD_isError (compressed_encoded_size ))
741+ compressed_encoded_size_zstd = ZSTD_compress (compressed_encoded_data , compressed_encoded_size_zstd , encoded_data , encoded_size , 3 );
742+ if (ZSTD_isError (compressed_encoded_size_zstd ))
740743 {
741744 ret = -1 ;
742745 goto exit ;
743746 }
744747 /* Have to cast after checking the error flags, not before */
745- compressed_encoded_size = (uint32_t )compressed_encoded_size ;
748+ compressed_encoded_size = (uint32_t )compressed_encoded_size_zstd ;
746749 break ;
747750 }
748751#endif
@@ -1207,11 +1210,13 @@ bool replay_check_same_timeline(bsv_movie_t *movie,
12071210 intfstream_seek (movie -> file , sizeof (uint32_t ), SEEK_CUR );
12081211 intfstream_seek (check_stream , sizeof (uint32_t ), SEEK_CUR );
12091212 }
1213+ keycount1 = UINT8_MAX ;
1214+ keycount2 = UINT8_MAX ;
12101215 if (intfstream_read (movie -> file , & keycount1 , 1 ) < 1 ||
12111216 intfstream_read (check_stream , & keycount2 , 1 ) < 1 ||
12121217 keycount1 != keycount2 )
12131218 {
1214- RARCH_ERR ("[Replay] Replay checkpoints disagree on key count, %d vs %d\n" , keycount1 , keycount2 );
1219+ RARCH_ERR ("[Replay] Replay checkpoints disagree on key count, %d vs %d (255 means read error) \n" , keycount1 , keycount2 );
12151220 ret = false;
12161221 goto exit ;
12171222 }
@@ -1658,6 +1663,10 @@ bool bsv_movie_read_deduped_state(bsv_movie_t *movie, uint8_t *encoded, size_t e
16581663 free (movie -> superblock_seq );
16591664 movie -> superblock_seq = NULL ;
16601665 }
1666+ if (!movie -> cur_save ) {
1667+ RARCH_ERR ("[STATESTREAM] movie has no current serialized save\n" );
1668+ goto exit ;
1669+ }
16611670 total_decode_count ++ ;
16621671 rmsgpack_dom_read_with (read_mem , & item , reader_state );
16631672 if (item .type != RDT_INT && item .type != RDT_UINT )
0 commit comments