summaryrefslogtreecommitdiff
path: root/ext/zlib
diff options
context:
space:
mode:
authorkatsu <katsu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-08-20 03:19:09 +0000
committerkatsu <katsu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-08-20 03:19:09 +0000
commit47778e27f9cfa2dc0c9e321cf89bd2a1a177567d (patch)
treeac99adc4e5b3cb6002972d870ca177015363e68d /ext/zlib
parentc59f1e6c900233cc3a970c9dc0bd630f33cd0463 (diff)
downloadruby-47778e27f9cfa2dc0c9e321cf89bd2a1a177567d.tar.gz
* ext/zlib/zlib.c: GzipReader#ungetc caused crc error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/zlib')
-rw-r--r--ext/zlib/zlib.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index c5e9e7437c..ad7e91e930 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -119,6 +119,7 @@ static void gzfile_read_header _((struct gzfile*));
static void gzfile_check_footer _((struct gzfile*));
static void gzfile_write _((struct gzfile*, Bytef*, uInt));
static long gzfile_read_more _((struct gzfile*));
+static void gzfile_calc_crc _((struct gzfile*, VALUE));
static VALUE gzfile_read _((struct gzfile*, int));
static VALUE gzfile_read_all _((struct gzfile*));
static void gzfile_ungetc _((struct gzfile*, int));
@@ -2068,6 +2069,21 @@ gzfile_read_more(gz)
return gz->z.buf_filled;
}
+static void
+gzfile_calc_crc(gz, str)
+ struct gzfile *gz;
+ VALUE str;
+{
+ if (RSTRING(str)->len <= gz->ungetc) {
+ gz->ungetc -= RSTRING(str)->len;
+ }
+ else {
+ gz->crc = crc32(gz->crc, RSTRING(str)->ptr + gz->ungetc,
+ RSTRING(str)->len - gz->ungetc);
+ gz->ungetc = 0;
+ }
+}
+
static VALUE
gzfile_read(gz, len)
struct gzfile *gz;
@@ -2090,13 +2106,7 @@ gzfile_read(gz, len)
}
dst = zstream_shift_buffer(&gz->z, len);
- if (RSTRING(dst)->len <= gz->ungetc) {
- gz->ungetc -= RSTRING(dst)->len;
- }
- else {
- gz->crc = crc32(gz->crc, RSTRING(dst)->ptr + gz->ungetc,
- RSTRING(dst)->len - gz->ungetc);
- }
+ gzfile_calc_crc(gz, dst);
OBJ_TAINT(dst); /* for safe */
return dst;
@@ -2119,13 +2129,7 @@ gzfile_read_all(gz)
}
dst = zstream_detach_buffer(&gz->z);
- if (RSTRING(dst)->len <= gz->ungetc) {
- gz->ungetc -= RSTRING(dst)->len;
- }
- else {
- gz->crc = crc32(gz->crc, RSTRING(dst)->ptr + gz->ungetc,
- RSTRING(dst)->len - gz->ungetc);
- }
+ gzfile_calc_crc(gz, dst);
OBJ_TAINT(dst); /* for safe */
return dst;
@@ -3008,8 +3012,7 @@ gzreader_skip_linebreaks(gz)
while (n++, *(p++) == '\n') {
if (n >= gz->z.buf_filled) {
str = zstream_detach_buffer(&gz->z);
- gz->crc = crc32(gz->crc, RSTRING(str)->ptr,
- RSTRING(str)->len);
+ gzfile_calc_crc(gz, str);
while (gz->z.buf_filled == 0) {
if (GZFILE_IS_FINISHED(gz)) return;
gzfile_read_more(gz);
@@ -3020,7 +3023,7 @@ gzreader_skip_linebreaks(gz)
}
str = zstream_shift_buffer(&gz->z, n - 1);
- gz->crc = crc32(gz->crc, RSTRING(str)->ptr, RSTRING(str)->len);
+ gzfile_calc_crc(gz, str);
}
static VALUE