From 11afc7b734d95b6b270d16eac6ad338ad38cd87a Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Tue, 22 Nov 2022 18:42:07 +0100
Subject: [PATCH] test_open_options: test TIFFOpenOptionsSetMaxSingleMemAlloc()
---
test/test_open_options.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/test/test_open_options.c b/test/test_open_options.c
index cec280fc..fbd32e64 100644
--- a/test/test_open_options.c
+++ b/test/test_open_options.c
@@ -62,7 +62,7 @@ static int myErrorHandler(TIFF* tiff, void* user_data, const char* module, const
return 1;
}
-int test_error_handler()
+static int test_error_handler()
{
int ret = 0;
char error_buffer[ERROR_STRING_SIZE] = {0};
@@ -132,9 +132,28 @@ int test_error_handler()
return ret;
}
+static int test_TIFFOpenOptionsSetMaxSingleMemAlloc(tmsize_t limit)
+{
+ int ret = 0;
+ TIFFOpenOptions* opts = TIFFOpenOptionsAlloc();
+ assert(opts);
+ TIFFOpenOptionsSetMaxSingleMemAlloc(opts, limit);
+ TIFF* tif = TIFFOpenExt("test_error_handler.tif", "w", opts);
+ TIFFOpenOptionsFree(opts);
+ if( tif != NULL )
+ {
+ fprintf(stderr, "Expected TIFFOpenExt() to fail due to memory limitation\n");
+ ret = 1;
+ TIFFClose(tif);
+ }
+ unlink("test_error_handler.tif");
+ return ret;
+}
+
int main()
{
int ret = 0;
ret += test_error_handler();
+ ret += test_TIFFOpenOptionsSetMaxSingleMemAlloc(1);
return ret;
}