Bug 703301 - Wrong size check for display_callback_v2_s
Summary: Wrong size check for display_callback_v2_s
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.53.0
Hardware: All All
: P4 major
Assignee: Robin Watts
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-22 09:03 UTC by Pino Toscano
Modified: 2021-01-15 16:04 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
[PATCH] Drop bogus size check (602 bytes, patch)
2020-12-22 09:03 UTC, Pino Toscano
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pino Toscano 2020-12-22 09:03:32 UTC
Created attachment 20385 [details]
[PATCH] Drop bogus size check

Commit eed3bad23510e59278bdaa5f7d0ab01fc1a1c21b [1] introduces a display_callback v3, leaving the support for the former display_callback now known as v2.
The problem is that the struct sizes check added for v2 compatibility is broken:
in the "display_check_structure" function of devices/gdevdsp.c there is:

static int display_check_structure(gx_device_display *ddev)
[...]
    else if (ddev->callback->size == sizeof(struct display_callback_v2_s)) {
        /* V2 structure with added display_separation callback */
        if (ddev->callback->size != sizeof(display_callback))
            return_error(gs_error_rangecheck);
[...]

Considering that:
- sizeof(struct display_callback_v2_s) != sizeof(display_callback);
  the addition to new stuff to display_callback was the reason for the
  new struct in the first place, so of course the two structs do not
  have the same size
- the last libspectre build uses display_callback v2, so the check:
  ddev->callback->size == sizeof(struct display_callback_v2_s)
  is true
then the check "ddev->callback->size != sizeof(display_callback)" will be always false, and thus always returning errors when running an application/library that was built with display_callback v2.

It looks to me it was a simple copy&paste mistake, and indeed the aforementioned check makes display_callback v2 working again; attached the easy patch for this.

[1] http://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=eed3bad23510e59278bdaa5f7d0ab01fc1a1c21b
Comment 1 Pino Toscano 2020-12-22 09:19:36 UTC
Sorry, when I wrote "the last libspectre build" I actually meant "any application/library built with v2".
Comment 2 Ray Johnston 2020-12-22 17:40:06 UTC
Assigning to Robin since he was the last person to touch that code.

The check would be required if v3 is NOT backward compatible with callers
still using v2 (although the check is not present for callers using v1).
Comment 3 Robin Watts 2021-01-15 16:04:16 UTC
Fixed in:

commit 364a3883326b90bf078d488909ba3203450da3d3
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 15 12:10:58 2021 +0000

    Bug 703301: Fix logic error in display device structure checks.

    Thanks to Pino Toscano for spotting this.

Many thanks!