@@ -408,7 +408,8 @@ static int read_header_loose_standard(
408408static int read_header_loose (git_rawobj * out , git_buf * loc )
409409{
410410 unsigned char obj [1024 ];
411- int fd , obj_len , error ;
411+ ssize_t obj_len ;
412+ int fd , error ;
412413
413414 assert (out && loc );
414415
@@ -417,10 +418,14 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
417418
418419 out -> data = NULL ;
419420
420- if ((error = fd = git_futils_open_ro (loc -> ptr )) < 0 ||
421- (error = obj_len = p_read (fd , obj , sizeof (obj ))) < 0 )
421+ if ((error = fd = git_futils_open_ro (loc -> ptr )) < 0 )
422422 goto done ;
423423
424+ if ((obj_len = p_read (fd , obj , sizeof (obj ))) < 0 ) {
425+ error = (int )obj_len ;
426+ goto done ;
427+ }
428+
424429 if (!is_zlib_compressed_data (obj , (size_t )obj_len ))
425430 error = read_header_loose_packlike (out , obj , (size_t )obj_len );
426431 else
@@ -871,6 +876,8 @@ static int loose_backend__readstream_read(
871876 size_t start_remain = stream -> start_len - stream -> start_read ;
872877 int total = 0 , error ;
873878
879+ buffer_len = min (buffer_len , INT_MAX );
880+
874881 /*
875882 * if we read more than just the header in the initial read, play
876883 * that back for the caller.
@@ -882,20 +889,20 @@ static int loose_backend__readstream_read(
882889 buffer += chunk ;
883890 stream -> start_read += chunk ;
884891
885- total += chunk ;
892+ total += ( int ) chunk ;
886893 buffer_len -= chunk ;
887894 }
888895
889896 if (buffer_len ) {
890- size_t chunk = min ( buffer_len , INT_MAX ) ;
897+ size_t chunk = buffer_len ;
891898
892899 if ((error = git_zstream_get_output (buffer , & chunk , & stream -> zstream )) < 0 )
893900 return error ;
894901
895- total += chunk ;
902+ total += ( int ) chunk ;
896903 }
897904
898- return total ;
905+ return ( int ) total ;
899906}
900907
901908static void loose_backend__readstream_free (git_odb_stream * _stream )
0 commit comments