From 7b847a10dbb70be6f66b934224d4954892400621 Mon Sep 17 00:00:00 2001 From: Ralph Little Date: Wed, 15 Mar 2023 20:02:18 -0700 Subject: [PATCH 1/2] epsonds: Ensure that image acquired before sane_read() can be called. --- backend/epsonds.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/epsonds.c b/backend/epsonds.c index 72d01d8a7..4d2c79977 100644 --- a/backend/epsonds.c +++ b/backend/epsonds.c @@ -2629,22 +2629,34 @@ sane_get_parameters(SANE_Handle handle, SANE_Parameters *params) if (params == NULL) DBG(1, "%s: params is NULL\n", __func__); + /* - * If sane_start was already called, then just retrieve the parameters - * from the scanner data structure + * If scanning then make sure that we acquire an image before we proceed + * if we didn't before. It is unlikely that s->scanning can be true and we have + * not acquired an image yet but let us be sure. + * + * Otherwise, we will generate parameters purely from the current settings + * rather than anything we got from the current image. + * */ - if (s->scanning) { + if (s->scanning) + { DBG(5, "scan in progress, returning saved params structure\n"); + + if (s->acquirePage == 0) + { + SANE_Status status = get_next_image(s); + if (status != SANE_STATUS_GOOD) + { + DBG(1, "failed to acquire image for parameters.\n"); + return status; + } + } } else { /* otherwise initialize the params structure */ eds_init_parameters(s); } - - SANE_Status status = SANE_STATUS_GOOD; - - status = get_next_image(s); - // if size auto, update page size value if(s->val[OPT_ADF_CRP].w) { @@ -2707,7 +2719,7 @@ sane_get_parameters(SANE_Handle handle, SANE_Parameters *params) print_params(s->params); DBG(20, "s->params.line = %d s->params.bytes_per_line = %d s->params.pixels_per_line = %d \n", s->params.lines, s->params.bytes_per_line , s->params.pixels_per_line ); - return status; + return SANE_STATUS_GOOD; } @@ -3305,6 +3317,10 @@ sane_start(SANE_Handle handle) s->scanning = 1; s->dummy = 0; s->scanEnd = 0; + + /* acquire the first image. */ + status = get_next_image(s); + end: if (status != SANE_STATUS_GOOD) { DBG(1, "%s: start failed: %s\n", __func__, sane_strstatus(status)); From 88ca2d07a1525511c1fa3169e7d383f9b1ea91e4 Mon Sep 17 00:00:00 2001 From: Ralph Little Date: Thu, 16 Mar 2023 22:24:13 -0700 Subject: [PATCH 2/2] saned/epsonds: Fixes for ring buffer issues and improper early termination. --- backend/epsonds.c | 10 ++++++---- frontend/saned.c | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/epsonds.c b/backend/epsonds.c index 4d2c79977..6901a8dbe 100644 --- a/backend/epsonds.c +++ b/backend/epsonds.c @@ -3613,10 +3613,12 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, SANE_Int *le // data is empty fin if (read == 0) { *length = 0; - eds_ring_flush(s->current); - eds_ring_destory(s->current); - DBG(18, "returns EOF 2\n"); - return SANE_STATUS_EOF; + + // This is silly: we already established above that there is data available. +// eds_ring_flush(s->current); +// eds_ring_destory(s->current); + DBG(18, "Couldn't read anything from ring buffer: probably not enough capacity to receive.\n"); + return SANE_STATUS_GOOD; } *length = read; diff --git a/frontend/saned.c b/frontend/saned.c index 575499861..a133b1385 100644 --- a/frontend/saned.c +++ b/frontend/saned.c @@ -1771,6 +1771,10 @@ do_scan (Wire * w, int h, int data_fd) /* get more input data */ /* reserve 4 bytes to store the length of the data record: */ + + /* NOTE: it seems to me that we could dispense with the record if we read nothing from sane_read() */ + /* Consider an optimization whereby we add nothing to the ring buffer in this case. */ + /* I do need to check the semantics of this though. [RL] */ i = reader; reader += 4; if (reader >= (int) buffer_size)