summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2011-03-11 21:13:19 +0000
committerKim Woelders <kim@woelders.dk>2011-03-11 21:13:19 +0000
commita1a018317a29c6b5b6d0accf1d9deb7697245923 (patch)
tree0fd9d6b8e35b7196ad19e89ed45828c4d6cf2d7c
parent5983044ae479efc47f2b6130c865b9252f9e9174 (diff)
downloadimlib2-a1a018317a29c6b5b6d0accf1d9deb7697245923.tar.gz
Fix pnm image loading in certain situations (ticket 721).
"It fails with "large" images, written with multiple pixels on the same line." Patch by quentin.stievenart@gmail.com SVN revision: 57697
-rw-r--r--src/modules/loaders/loader_pnm.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index 229a270..04ea4e4 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -215,15 +215,22 @@ load(ImlibImage * im, ImlibProgressFunction progress,
x = 0;
while (x < w)
{
- if (!buf[i]) /* fill buffer */
+ int k;
+ /* check 4 chars ahead to see if we need to
+ fill the buffer */
+ for (k = 0; k < 4; k++)
{
- if (!fgets(buf, 255, f))
+ if (!buf[i+k]) /* fill buffer */
{
- free(idata);
- fclose(f);
- return 0;
+ if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
+ {
+ free(idata);
+ fclose(f);
+ return 0;
+ }
+ i = 0;
+ break;
}
- i = 0;
}
while (buf[i] && isspace(buf[i]))
i++;
@@ -308,15 +315,22 @@ load(ImlibImage * im, ImlibProgressFunction progress,
x = 0;
while (x < w3)
{
- if (!buf[i]) /* fill buffer */
+ int k;
+ /* check 4 chars ahead to see if we need to
+ fill the buffer */
+ for (k = 0; k < 4; k++)
{
- if (!fgets(buf, 255, f))
+ if (!buf[i+k]) /* fill buffer */
{
- free(idata);
- fclose(f);
- return 0;
+ if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
+ {
+ free(idata);
+ fclose(f);
+ return 0;
+ }
+ i = 0;
+ break;
}
- i = 0;
}
while (buf[i] && isspace(buf[i]))
i++;