Skip to content

Fix #76342: file_get_contents waits twice specified timeout #4486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Jul 29, 2019

Currently, if getting the response headers fails, we are still trying to read past them to get the content. Is that logical? 🤔

That's the cause of the fixed bug : the current behavior makes 2 call to php_stream_get_line, thus "applying" 2 times the timeout. I guess that in the particular described setup, the end of stream is not detected. However, the timeout being applied 2 times is not coherent at all.

I just moved the /* read past HTTP headers */ code block so it is executed only if getting the headers was successful. We can also fix it by forcing $stream->eof = 1; when the first call fails but I guess that's dirtier.

I know close to nothing about C and PHP source code but at least the test can be used if it can be fixed in a better way 😄

@fancyweb fancyweb force-pushed the http-fopen-wrapper-timeout branch from 691c6d3 to ba5648d Compare August 1, 2019 08:47
@fancyweb fancyweb force-pushed the http-fopen-wrapper-timeout branch from ba5648d to 86e6cff Compare August 1, 2019 08:51
@@ -726,6 +726,11 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
}
ZVAL_STRINGL(&http_response, tmp_line, tmp_line_len);
zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response);
} else {
php_stream_close(stream);
stream = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While merging this up into 7.4, I found that we have 41c4816 there, which should have much the same effect -- the main difference I see is that it does not close and null the stream. The EOF branch below also doesn't do this. I'm wondering if it's necessary?

Copy link
Contributor Author

@fancyweb fancyweb Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to be coherent with lines 851 & 852 (

php_stream_close(stream);
)

Removing both lines doesn't work because the stream is not technically EOF, so it still goes through the second call, thus applying 2 times the timeout.

Only php_stream_close(stream) -> seg fault
Only stream = null -> seems to work

@nikic
Copy link
Member

nikic commented Sep 17, 2019

Sorry for the delay, I forgot about this. Now merged as e691a98 into 7.2+. Thanks!

@nikic nikic closed this Sep 17, 2019
@fancyweb fancyweb deleted the http-fopen-wrapper-timeout branch September 17, 2019 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants