@@ -841,9 +841,13 @@ static int php_zstd_decomp_close(php_stream *stream, int close_handle)
841841 return EOF ;
842842 }
843843
844+ int ret = 0 ;
845+
844846 if (close_handle ) {
845847 if (self -> stream ) {
846- php_stream_close (self -> stream );
848+ if (php_stream_close (self -> stream )) {
849+ ret = EOF ;
850+ }
847851 self -> stream = NULL ;
848852 }
849853 }
@@ -854,7 +858,7 @@ static int php_zstd_decomp_close(php_stream *stream, int close_handle)
854858 efree (self );
855859 stream -> abstract = NULL ;
856860
857- return EOF ;
861+ return ret ;
858862}
859863
860864static int php_zstd_comp_flush_or_end (php_zstd_stream_data * self , int end )
@@ -872,9 +876,15 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
872876 if (ZSTD_isError (res )) {
873877 ZSTD_WARNING ("zstd: %s" , ZSTD_getErrorName (res ));
874878 ret = EOF ;
879+ break ;
880+ }
881+ if (self -> ctx .output .pos
882+ && (size_t ) php_stream_write (self -> stream , self -> ctx .output .dst ,
883+ self -> ctx .output .pos )
884+ != self -> ctx .output .pos ) {
885+ ret = EOF ;
886+ break ;
875887 }
876- php_stream_write (self -> stream ,
877- self -> ctx .output .dst , self -> ctx .output .pos );
878888 } while (res > 0 );
879889
880890 return ret ;
@@ -897,11 +907,13 @@ static int php_zstd_comp_close(php_stream *stream, int close_handle)
897907 return EOF ;
898908 }
899909
900- php_zstd_comp_flush_or_end (self , 1 );
910+ int ret = php_zstd_comp_flush_or_end (self , 1 );
901911
902912 if (close_handle ) {
903913 if (self -> stream ) {
904- php_stream_close (self -> stream );
914+ if (php_stream_close (self -> stream )) {
915+ ret = EOF ;
916+ }
905917 self -> stream = NULL ;
906918 }
907919 }
@@ -911,7 +923,7 @@ static int php_zstd_comp_close(php_stream *stream, int close_handle)
911923 efree (self );
912924 stream -> abstract = NULL ;
913925
914- return EOF ;
926+ return ret ;
915927}
916928
917929
@@ -997,8 +1009,14 @@ php_zstd_comp_write(php_stream *stream, const char *buf, size_t count)
9971009 return -1 ;
9981010#endif
9991011 }
1000- php_stream_write (self -> stream ,
1001- self -> ctx .output .dst , self -> ctx .output .pos );
1012+ if (self -> ctx .output .pos
1013+ && (size_t ) php_stream_write (self -> stream , self -> ctx .output .dst ,
1014+ self -> ctx .output .pos )
1015+ != self -> ctx .output .pos ) {
1016+ #if PHP_VERSION_ID >= 70400
1017+ return -1 ;
1018+ #endif
1019+ }
10021020
10031021 } while (res > 0 );
10041022
0 commit comments