libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 21a2b41325ef87f55e3755a14f46f6f91dae599e
parent 8bb8362db8fee5da97c180abe6dd5cd64c0ad2b0
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 31 Jul 2012 21:19:49 +0000

LRN: pos is the position in the file (i.e. file pointer offset from the
beginning of the file).
buffer_pos is the position within the buffer.
buffer_bytes is the length of the buffer.

When we run out of bytes to give, this:
old_off = bfds->fpos + bfds->buffer_pos + bfds->buffer_bytes;
will overshoot the position, because bfds->buffer_pos is equal to
bfds->buffer_bytes.


Same for
if ( (bfds->buffer_bytes == bfds->buffer_pos) && (0 !=
bfds_pick_next_buffer_at (bfds, bfds->fpos + bfds->buffer_pos +
bfds->buffer_bytes)) )



Diffstat:
Msrc/main/extractor_datasource.c | 10+++++++---
Msrc/main/extractor_plugin_main.c | 17+++++++++++++----
2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c @@ -406,7 +406,7 @@ bfds_read (struct BufferedFileDataSource *bfds, size_t avail; size_t ret; - old_off = bfds->fpos + bfds->buffer_pos + bfds->buffer_bytes; + old_off = bfds->fpos + bfds->buffer_pos; if (old_off == bfds->fsize) return 0; /* end of stream */ ret = 0; @@ -414,7 +414,7 @@ bfds_read (struct BufferedFileDataSource *bfds, { if ( (bfds->buffer_bytes == bfds->buffer_pos) && (0 != bfds_pick_next_buffer_at (bfds, - bfds->fpos + bfds->buffer_pos + bfds->buffer_bytes)) ) + bfds->fpos + bfds->buffer_bytes)) ) { /* revert to original position, invalidate buffer */ bfds->fpos = old_off; @@ -1053,8 +1053,12 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename, int fd; struct stat sb; int64_t fsize; + int winmode = 0; +#if WINDOWS + winmode = O_BINARY; +#endif - if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE))) + if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE | winmode))) { LOG_STRERROR_FILE ("open", filename); return NULL; diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c @@ -33,9 +33,11 @@ #include "extractor_plugin_main.h" #include <dirent.h> #include <sys/types.h> +#if LINUX #include <sys/wait.h> #include <sys/shm.h> #include <signal.h> +#endif /** @@ -363,9 +365,16 @@ handle_init_message (struct ProcessingContext *pc) pc->shm_map_size = init.shm_map_size; #if WINDOWS + /* FIXME: storing pointer in an int */ + pc->shm_id = OpenFileMapping (FILE_MAP_READ, FALSE, shm_name); + if (NULL == pc->shm_id) + return -1; pc->shm = MapViewOfFile (pc->shm_id, FILE_MAP_READ, 0, 0, 0); if (NULL == pc->shm) + { + CloseHandle (pc->shm_id); return -1; + } #else pc->shm_id = shm_open (shm_name, O_RDONLY, 0); if (-1 == pc->shm_id) @@ -604,8 +613,9 @@ read_plugin_data (int fd) LOG_STRERROR ("malloc"); return NULL; } - GetSystemInfo (&si); - ret->allocation_granularity = si.dwAllocationGranularity; + memset (ret, 0, sizeof (struct EXTRACTOR_PluginList)); + /*GetSystemInfo (&si); + ret->allocation_granularity = si.dwAllocationGranularity;*/ EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); if (NULL == (ret->libname = malloc (i))) { @@ -668,8 +678,7 @@ RundllEntryPoint (HWND hwnd, close (out); return; } - plugin_main (plugin, - in, out); + EXTRACTOR_plugin_main_ (plugin, in, out); close (in); close (out); }