From: Tilman Sauerbeck Date: Fri, 18 Aug 2006 13:38:30 +0000 (+0200) Subject: Check the error flag when reading data. X-Git-Tag: ruby-vorbistagger-0.0.1~10 X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=commitdiff_plain;h=d167e476209adeab15e067425b941509b1ed90f4 Check the error flag when reading data. --- diff --git a/ext/vcedit.c b/ext/vcedit.c index ce5cb10..cf63e74 100644 --- a/ext/vcedit.c +++ b/ext/vcedit.c @@ -240,7 +240,7 @@ _fetch_next_packet (vcedit_state *s, ogg_packet *p, ogg_page *page) bytes = fread (buffer, 1, CHUNKSIZE, s->in); ogg_sync_wrote (&s->oy, bytes); - if (!bytes && feof (s->in)) + if (!bytes && (feof (s->in) || ferror (s->in))) return 0; } @@ -276,7 +276,7 @@ vcedit_open (vcedit_state *s) do { /* Bail if we don't find data in the first 40 kB */ - if (feof (s->in) || total >= (CHUNKSIZE * 10)) { + if (feof (s->in) || ferror (s->in) || total >= (CHUNKSIZE * 10)) { ogg_sync_clear (&s->oy); return VCEDIT_ERR_INVAL; @@ -318,6 +318,11 @@ vcedit_open (vcedit_state *s) header = &header_comments; while (i < 2) { + if (feof (s->in) || ferror (s->in)) { + ret = VCEDIT_ERR_INVAL; + goto err; + } + while (i < 2) { int result; @@ -353,13 +358,8 @@ vcedit_open (vcedit_state *s) } buffer = ogg_sync_buffer (&s->oy, CHUNKSIZE); - bytes = fread (buffer, 1, CHUNKSIZE, s->in); - - if (!bytes && feof (s->in) && i < 2) { - ret = VCEDIT_ERR_INVAL; - goto err; - } + bytes = fread (buffer, 1, CHUNKSIZE, s->in); ogg_sync_wrote (&s->oy, bytes); } @@ -540,6 +540,9 @@ vcedit_write (vcedit_state *s) bytes = fread (buffer, 1, CHUNKSIZE, s->in); ogg_sync_wrote (&s->oy, bytes); + if (ferror (s->in)) + goto cleanup; + s->eosin = !bytes && feof (s->in); } while (!s->eosin);