@@ -237,29 +237,29 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
237
237
zend_op_array * ret ;
238
238
uint32_t line ;
239
239
char * bufptr , * endptr ;
240
- int size ;
240
+ size_t len ;
241
+
242
+ /* Copy file contents before calling original compile_file,
243
+ * as it may invalidate the file handle. */
244
+ if (zend_stream_fixup (file , & bufptr , & len ) == FAILURE ) {
245
+ if (type == ZEND_REQUIRE ) {
246
+ zend_message_dispatcher (ZMSG_FAILED_REQUIRE_FOPEN , file -> filename );
247
+ zend_bailout ();
248
+ } else {
249
+ zend_message_dispatcher (ZMSG_FAILED_INCLUDE_FOPEN , file -> filename );
250
+ }
251
+ }
252
+
253
+ data .buf = estrndup (bufptr , len );
254
+ data .len = len ;
241
255
242
256
ret = PHPDBG_G (compile_file )(file , type );
243
257
if (ret == NULL ) {
258
+ efree (data .buf );
244
259
return ret ;
245
260
}
246
261
247
- if (file -> type == ZEND_HANDLE_MAPPED ) {
248
- data .len = file -> handle .stream .mmap .len ;
249
- data .buf = emalloc (data .len + 1 );
250
- memcpy (data .buf , file -> handle .stream .mmap .buf , data .len );
251
- } else {
252
- if (file -> type == ZEND_HANDLE_FILENAME ) {
253
- zend_stream_open (file -> filename , file );
254
- }
255
-
256
- size = file -> handle .stream .fsizer (file -> handle .stream .handle );
257
- data .buf = emalloc (size + 1 );
258
- data .len = file -> handle .stream .reader (file -> handle .stream .handle , data .buf , size );
259
- }
260
-
261
- memset (data .buf + data .len , 0 , 1 );
262
-
262
+ data .buf [data .len ] = '\0' ;
263
263
data .line [0 ] = 0 ;
264
264
* (dataptr = emalloc (sizeof (phpdbg_file_source ) + sizeof (uint32_t ) * data .len )) = data ;
265
265
0 commit comments