summaryrefslogtreecommitdiff
path: root/fitz/filt_basic.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-12-08 15:32:03 +0100
committerTor Andersson <tor.andersson@artifex.com>2011-12-08 21:46:55 +0100
commit34c971b594bad41fa6c2ad4a9798e5a18de129b5 (patch)
tree0c3956c35f827d1649e0520abf18974a4e0ec8e2 /fitz/filt_basic.c
parente64a57b1e9c2ba6c6f54eff73c414be9e78dafbe (diff)
downloadmupdf-34c971b594bad41fa6c2ad4a9798e5a18de129b5.tar.xz
Throw exceptions for read errors.
Diffstat (limited to 'fitz/filt_basic.c')
-rw-r--r--fitz/filt_basic.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c
index 0842ec36..1ab70f7f 100644
--- a/fitz/filt_basic.c
+++ b/fitz/filt_basic.c
@@ -22,8 +22,6 @@ read_null(fz_stream *stm, unsigned char *buf, int len)
struct null_filter *state = stm->state;
int amount = MIN(len, state->remain);
int n = fz_read(state->chain, buf, amount);
- if (n < 0)
- return fz_error_note(n, "read error in null filter");
state->remain -= n;
return n;
}
@@ -33,7 +31,6 @@ close_null(fz_stream *stm)
{
struct null_filter *state = stm->state;
fz_stream *chain = state->chain;
-
fz_free(stm->ctx, state);
fz_close(chain);
}
@@ -127,7 +124,7 @@ read_ahxd(fz_stream *stm, unsigned char *buf, int len)
}
else if (!iswhite(c))
{
- return fz_error_make("bad data in ahxd: '%c'", c);
+ fz_throw(stm->ctx, "bad data in ahxd: '%c'", c);
}
}
@@ -139,7 +136,6 @@ close_ahxd(fz_stream *stm)
{
fz_ahxd *state = stm->state;
fz_stream *chain = state->chain;
-
fz_free(stm->ctx, state);
fz_close(chain);
}
@@ -233,7 +229,7 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len)
case 0:
break;
case 1:
- return fz_error_make("partial final byte in a85d");
+ fz_throw(stm->ctx, "partial final byte in a85d");
case 2:
word = word * (85 * 85 * 85) + 0xffffff;
state->bp[0] = word >> 24;
@@ -261,7 +257,7 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len)
else if (!iswhite(c))
{
- return fz_error_make("bad data in a85d: '%c'", c);
+ fz_throw(stm->ctx, "bad data in a85d: '%c'", c);
}
while (state->rp < state->wp && p < ep)
@@ -330,7 +326,7 @@ read_rld(fz_stream *stm, unsigned char *buf, int len)
state->n = 257 - state->run;
state->c = fz_read_byte(state->chain);
if (state->c < 0)
- return fz_error_make("premature end of data in run length decode");
+ fz_throw(stm->ctx, "premature end of data in run length decode");
}
}
@@ -340,7 +336,7 @@ read_rld(fz_stream *stm, unsigned char *buf, int len)
{
int c = fz_read_byte(state->chain);
if (c < 0)
- return fz_error_make("premature end of data in run length decode");
+ fz_throw(stm->ctx, "premature end of data in run length decode");
*p++ = c;
state->n--;
}
@@ -398,14 +394,8 @@ static int
read_arc4(fz_stream *stm, unsigned char *buf, int len)
{
fz_arc4c *state = stm->state;
- int n;
-
- n = fz_read(state->chain, buf, len);
- if (n < 0)
- return fz_error_note(n, "read error in arc4 filter");
-
+ int n = fz_read(state->chain, buf, len);
fz_arc4_encrypt(&state->arc4, buf, buf, n);
-
return n;
}
@@ -456,7 +446,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
{
int c = fz_read_byte(state->chain);
if (c < 0)
- return fz_error_make("premature end in aes filter");
+ fz_throw(stm->ctx, "premature end in aes filter");
state->iv[state->ivcount++] = c;
}
@@ -466,12 +456,10 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
while (p < ep)
{
int n = fz_read(state->chain, state->bp, 16);
- if (n < 0)
- return fz_error_note(n, "read error in aes filter");
- else if (n == 0)
+ if (n == 0)
return p - buf;
else if (n < 16)
- return fz_error_make("partial block in aes filter");
+ fz_throw(stm->ctx, "partial block in aes filter");
aes_crypt_cbc(&state->aes, AES_DECRYPT, 16, state->iv, state->bp, state->bp);
state->rp = state->bp;
@@ -482,7 +470,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
{
int pad = state->bp[15];
if (pad < 1 || pad > 16)
- return fz_error_make("aes padding out of range: %d", pad);
+ fz_throw(stm->ctx, "aes padding out of range: %d", pad);
state->wp -= pad;
}