mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 12:55:59 +01:00
Cover all cases of read.
Files smaller than GT_MAX_READ cause guess_type to hang in an endless loop. Closes: #285
This commit is contained in:
parent
a6e6c3f108
commit
9765b43113
1 changed files with 5 additions and 4 deletions
|
@ -538,17 +538,18 @@ guess_type(const char* path)
|
||||||
const int fd = fileno(f);
|
const int fd = fileno(f);
|
||||||
guchar* content = NULL;
|
guchar* content = NULL;
|
||||||
size_t length = 0u;
|
size_t length = 0u;
|
||||||
while (uncertain == TRUE && length < GT_MAX_READ) {
|
ssize_t bytes_read = -1;
|
||||||
|
while (uncertain == TRUE && length < GT_MAX_READ && bytes_read != 0) {
|
||||||
g_free((void*)content_type);
|
g_free((void*)content_type);
|
||||||
content_type = NULL;
|
content_type = NULL;
|
||||||
|
|
||||||
content = g_realloc(content, length + BUFSIZ);
|
content = g_realloc(content, length + BUFSIZ);
|
||||||
const ssize_t r = read(fd, content + length, BUFSIZ);
|
bytes_read = read(fd, content + length, BUFSIZ);
|
||||||
if (r == -1) {
|
if (bytes_read == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
length += r;
|
length += bytes_read;
|
||||||
content_type = g_content_type_guess(NULL, content, length, &uncertain);
|
content_type = g_content_type_guess(NULL, content, length, &uncertain);
|
||||||
girara_debug("new guess: %s uncertain: %d, read: %zu\n", content_type, uncertain, length);
|
girara_debug("new guess: %s uncertain: %d, read: %zu\n", content_type, uncertain, length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue