Bug 703301

Summary: Wrong size check for display_callback_v2_s
Product: Ghostscript Reporter: Pino Toscano <toscano.pino>
Component: GeneralAssignee: Robin Watts <robin.watts>
Status: RESOLVED FIXED    
Severity: major CC: robin.watts
Priority: P4    
Version: 9.53.0   
Hardware: All   
OS: All   
Customer: Word Size: ---
Attachments: [PATCH] Drop bogus size check

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!