summaryrefslogtreecommitdiff
path: root/libopenjpeg
diff options
context:
space:
mode:
authorJulien Malik <julien.malik@paraiso.me>2011-11-24 15:30:09 +0000
committerJulien Malik <julien.malik@paraiso.me>2011-11-24 15:30:09 +0000
commitc974cb1b8ebe678fe126a7392d0b8279bb154ebc (patch)
tree4417d914395094b0f0a9a2cf5cf78a7524054a87 /libopenjpeg
parent20c05a3addd3b89756968676199db3a3f976f288 (diff)
[trunk] support seeking in files larger than 2 GB
Diffstat (limited to 'libopenjpeg')
-rw-r--r--libopenjpeg/openjpeg.c20
-rw-r--r--libopenjpeg/opj_includes.h1
2 files changed, 20 insertions, 1 deletions
diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c
index 73b136d6..f1efde1f 100644
--- a/libopenjpeg/openjpeg.c
+++ b/libopenjpeg/openjpeg.c
@@ -165,7 +165,25 @@ OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
{
- if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
+ /*
+ * p_nb_bytes is 'OPJ_SIZE_T' but fseek takes a 'signed long'
+ *
+ * As such, fseek can seek to a maximum of 2^31-1 bytes (2 GB)
+ * To support seeking in files between 2 GB and 4 GB :
+ * - first, do a seek with the max supported by fseek
+ * - secondly, seek of the remaining bytes
+ */
+ if (p_nb_bytes > LONG_MAX) {
+ if (fseek(p_user_data,LONG_MAX,SEEK_SET)) {
+ return EXIT_FAILURE;
+ }
+ p_nb_bytes -= LONG_MAX;
+
+ if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
+ return EXIT_FAILURE;
+ }
+ }
+ else if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
return EXIT_FAILURE;
}
diff --git a/libopenjpeg/opj_includes.h b/libopenjpeg/opj_includes.h
index d94237e7..8aefbafe 100644
--- a/libopenjpeg/opj_includes.h
+++ b/libopenjpeg/opj_includes.h
@@ -41,6 +41,7 @@
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
+#include <limits.h>
/*
==========================================================