summaryrefslogtreecommitdiff
path: root/src/pdf_doc.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2018-01-20 18:46:41 +0000
committerVincent Sanders <vince@kyllikki.org>2018-01-20 18:46:41 +0000
commit9f0e9af2eeb08abcaa4991ae4e87440dcba2ada1 (patch)
tree6b05ac4bedd3cc13f773e2b2adf03f7522c997c1 /src/pdf_doc.c
parent7967f13f57f08d2b8f38b8c52567d847933b79d8 (diff)
downloadlibnspdf-9f0e9af2eeb08abcaa4991ae4e87440dcba2ada1.tar.gz
libnspdf-9f0e9af2eeb08abcaa4991ae4e87440dcba2ada1.tar.bz2
correctly parse content streams for pages contents
Diffstat (limited to 'src/pdf_doc.c')
-rw-r--r--src/pdf_doc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/pdf_doc.c b/src/pdf_doc.c
index d7c7a0e..3e55e16 100644
--- a/src/pdf_doc.c
+++ b/src/pdf_doc.c
@@ -23,19 +23,26 @@ nspdferror
nspdf__stream_skip_ws(struct cos_stream *stream, strmoff_t *offset)
{
uint8_t c;
- /* TODO sort out keeping offset in range */
+
+ if ((*offset) >= stream->length) {
+ return NSPDFERROR_OK;
+ }
+
c = stream_byte(stream, *offset);
- while ((bclass[c] & (BC_WSPC | BC_CMNT) ) != 0) {
+ while (((*offset) < stream->length) &&
+ ((bclass[c] & (BC_WSPC | BC_CMNT) ) != 0)) {
(*offset)++;
/* skip comments */
- if ((bclass[c] & BC_CMNT) != 0) {
+ if (((*offset) < stream->length) &&
+ ((bclass[c] & BC_CMNT) != 0)) {
c = stream_byte(stream, *offset);
- while ((bclass[c] & BC_EOLM ) == 0) {
+ while ((*offset < stream->length) &&
+ ((bclass[c] & BC_EOLM ) == 0)) {
(*offset)++;
- c = stream_byte(stream, *offset);
+ c = stream_byte(stream, (*offset));
}
}
- c = stream_byte(stream, *offset);
+ c = stream_byte(stream, (*offset));
}
return NSPDFERROR_OK;
}