aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2023-01-02 23:40:54 +0000
committeryzrh <yzrh@noema.org>2023-01-03 00:13:56 +0000
commit4a02b8bfc74920291a62f06fff9cf6e6c4f23ace (patch)
tree13d450ececea1cda3f35c14a930b8042e41b280c /src
parent7d9d658461ed5b0118a1bff8f1df29fb00165a25 (diff)
downloadmelon-4a02b8bfc74920291a62f06fff9cf6e6c4f23ace.tar.gz
melon-4a02b8bfc74920291a62f06fff9cf6e6c4f23ace.tar.zst
Fix inconsistent whitespace detection in PDF parser.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r--src/pdf_parser.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/pdf_parser.c b/src/pdf_parser.c
index bb45e63..2585e6f 100644
--- a/src/pdf_parser.c
+++ b/src/pdf_parser.c
@@ -19,26 +19,35 @@ static void *
_memmem_whitespace(const void *p0, size_t s0, const void *p1, size_t s1)
{
const char whitespace[6] = {
- ' ',
- '\r',
- '\n',
- '\f',
- '\t',
- '\0'
+ 0x00,
+ 0x09,
+ 0x0a,
+ 0x0c,
+ 0x0d,
+ 0x20
};
- char tmp[s1 + 1];
- memcpy(tmp, p1, s1);
+ char *ret = NULL;
- char *ret;
+ char str[s1 + 1];
+ memcpy(str, p1, s1);
+
+ size_t tmp_size = 0;
+ char *tmp;
for (int i = 0; i < 6; i++) {
- tmp[s1] = whitespace[i];
- if ((ret = memmem(p0, s0, tmp, s1 + 1)) != NULL)
- return ret;
+ str[s1] = whitespace[i];
+
+ if ((tmp = memmem(p0, s0, str, s1 + 1)) == NULL)
+ continue;
+
+ if (tmp_size == 0 || (size_t) (tmp - (char *) p0) < tmp_size) {
+ tmp_size = tmp - (char *) p0;
+ ret = tmp;
+ }
}
- return NULL;
+ return ret;
}
static int