|
|
396e5c |
From d2f5d424ba8752f9a9e9dad410546ec1b46caa0a Mon Sep 17 00:00:00 2001
|
|
|
396e5c |
From: Adam Reichold <adam.reichold@t-online.de>
|
|
|
396e5c |
Date: Tue, 6 Nov 2018 09:08:06 +0100
|
|
|
396e5c |
Subject: [PATCH] pdfdetach: Check for valid file name of embedded file before
|
|
|
396e5c |
using it to determine save path.
|
|
|
396e5c |
|
|
|
396e5c |
Closes #660
|
|
|
396e5c |
---
|
|
|
396e5c |
utils/pdfdetach.cc | 24 ++++++++++++++++++------
|
|
|
396e5c |
1 file changed, 18 insertions(+), 6 deletions(-)
|
|
|
396e5c |
|
|
|
396e5c |
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
|
|
|
396e5c |
index a8720c64..71fa8608 100644
|
|
|
396e5c |
--- a/utils/pdfdetach.cc
|
|
|
396e5c |
+++ b/utils/pdfdetach.cc
|
|
|
396e5c |
@@ -191,14 +191,18 @@ int main(int argc, char *argv[]) {
|
|
|
396e5c |
fileSpec = static_cast<FileSpec *>(embeddedFiles->get(i));
|
|
|
396e5c |
printf("%d: ", i+1);
|
|
|
396e5c |
s1 = fileSpec->getFileName();
|
|
|
396e5c |
- if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff) {
|
|
|
396e5c |
+ if (!s1) {
|
|
|
396e5c |
+ exitCode = 3;
|
|
|
396e5c |
+ goto err2;
|
|
|
396e5c |
+ }
|
|
|
396e5c |
+ if (s1->hasUnicodeMarker()) {
|
|
|
396e5c |
isUnicode = gTrue;
|
|
|
396e5c |
j = 2;
|
|
|
396e5c |
} else {
|
|
|
396e5c |
isUnicode = gFalse;
|
|
|
396e5c |
j = 0;
|
|
|
396e5c |
}
|
|
|
396e5c |
- while (j < fileSpec->getFileName()->getLength()) {
|
|
|
396e5c |
+ while (j < s1->getLength()) {
|
|
|
396e5c |
if (isUnicode) {
|
|
|
396e5c |
u = ((s1->getChar(j) & 0xff) << 8) | (s1->getChar(j+1) & 0xff);
|
|
|
396e5c |
j += 2;
|
|
|
396e5c |
@@ -228,14 +232,18 @@ int main(int argc, char *argv[]) {
|
|
|
396e5c |
p = path;
|
|
|
396e5c |
}
|
|
|
396e5c |
s1 = fileSpec->getFileName();
|
|
|
396e5c |
- if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff) {
|
|
|
396e5c |
+ if (!s1) {
|
|
|
396e5c |
+ exitCode = 3;
|
|
|
396e5c |
+ goto err2;
|
|
|
396e5c |
+ }
|
|
|
396e5c |
+ if (s1->hasUnicodeMarker()) {
|
|
|
396e5c |
isUnicode = gTrue;
|
|
|
396e5c |
j = 2;
|
|
|
396e5c |
} else {
|
|
|
396e5c |
isUnicode = gFalse;
|
|
|
396e5c |
j = 0;
|
|
|
396e5c |
}
|
|
|
396e5c |
- while (j < fileSpec->getFileName()->getLength()) {
|
|
|
396e5c |
+ while (j < s1->getLength()) {
|
|
|
396e5c |
if (isUnicode) {
|
|
|
396e5c |
u = ((s1->getChar(j) & 0xff) << 8) | (s1->getChar(j+1) & 0xff);
|
|
|
396e5c |
j += 2;
|
|
|
396e5c |
@@ -276,14 +284,18 @@ int main(int argc, char *argv[]) {
|
|
|
396e5c |
} else {
|
|
|
396e5c |
p = path;
|
|
|
396e5c |
s1 = fileSpec->getFileName();
|
|
|
396e5c |
- if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff) {
|
|
|
396e5c |
+ if (!s1) {
|
|
|
396e5c |
+ exitCode = 3;
|
|
|
396e5c |
+ goto err2;
|
|
|
396e5c |
+ }
|
|
|
396e5c |
+ if (s1->hasUnicodeMarker()) {
|
|
|
396e5c |
isUnicode = gTrue;
|
|
|
396e5c |
j = 2;
|
|
|
396e5c |
} else {
|
|
|
396e5c |
isUnicode = gFalse;
|
|
|
396e5c |
j = 0;
|
|
|
396e5c |
}
|
|
|
396e5c |
- while (j < fileSpec->getFileName()->getLength()) {
|
|
|
396e5c |
+ while (j < s1->getLength()) {
|
|
|
396e5c |
if (isUnicode) {
|
|
|
396e5c |
u = ((s1->getChar(j) & 0xff) << 8) | (s1->getChar(j+1) & 0xff);
|
|
|
396e5c |
j += 2;
|
|
|
396e5c |
--
|
|
|
396e5c |
2.19.1
|
|
|
396e5c |
|