From 5e77ab948bbdcad0959ae5e0f24a2c669afbf62b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 29 Jul 2019 10:05:55 +0100 Subject: [PATCH] fix loop with malformed ppm skip_line in ppm parse was not testing for EOF, so it could get stuck with malformed files thanks Kyle-Kyle see https://github.com/libvips/libvips/issues/1377 --- .gitignore | 1 + ChangeLog | 1 + libvips/foreign/ppm.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bd3251b7..ad871beb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +fuzz/ .pytest_cache compile .pytest_cache diff --git a/ChangeLog b/ChangeLog index 46b4f861..e9135298 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - better early shutdown in readers - don't attempt to save large XMP to jpeg [tnextday] - always fetch HEIC metadata from the main image [zhoux2016] +- fix loop in malformed ppm [Kyle-Kyle] 24/5/19 started 8.8.1 - improve realpath() use on older libc diff --git a/libvips/foreign/ppm.c b/libvips/foreign/ppm.c index a5022e78..d5d1a626 100644 --- a/libvips/foreign/ppm.c +++ b/libvips/foreign/ppm.c @@ -89,7 +89,10 @@ static void skip_line( FILE *fp ) { - while( vips__fgetc( fp ) != '\n' ) + int ch; + + while( (ch = vips__fgetc( fp )) != '\n' && + ch != EOF ) ; }