Skip to content

Commit b930eb8

Browse files
committed
get_all_media(): Do not crash on custom page size range entries
The media-col-database IPP attribute contains one entry for each valid combination of page size dimensions, margins, and in some cases also media source and media type. If custom page sizes are supported, this is represented by one media-col-database entry (usually the last one) where the width and length dimensions are ranges, consisting of 2 numbers each. The get_all_media() tried to read those as normal intergers, getting back 0 and this cause NULL being returned by pwgMediaForSize() function and a segfault when trying to get the PWG name of the page size. This is now fixed by skipping the entry for the custom page size (actually we need to support custom page sizes).
1 parent 669abda commit b930eb8

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/backend_helper.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,23 @@ int get_all_media(PrinterCUPS *p, Media **medias)
12321232
int count = ippGetCount(mdb);
12331233
for (int i = 0; i < count; i++)
12341234
{
1235-
margin = g_new0(Margin, 1);
1236-
12371235
tuple = ippGetCollection(mdb, i);
12381236

1237+
attr = ippFindAttribute(tuple, "media-size", IPP_TAG_BEGIN_COLLECTION);
1238+
media_size = ippGetCollection(attr, 0);
1239+
attr = ippFindAttribute(media_size, "x-dimension", IPP_TAG_INTEGER);
1240+
width = ippGetInteger(attr, 0);
1241+
attr = ippFindAttribute(media_size, "y-dimension", IPP_TAG_INTEGER);
1242+
length = ippGetInteger(attr, 0);
1243+
1244+
if (width <= 0 || length <= 0)
1245+
continue;
1246+
1247+
pwg_media = pwgMediaForSize(width, length);
1248+
name = pwg_media->pwg;
1249+
1250+
margin = g_new0(Margin, 1);
1251+
12391252
attr = ippFindAttribute(tuple, "media-left-margin", IPP_TAG_INTEGER);
12401253
margin->left = ippGetInteger(attr, 0);
12411254
attr = ippFindAttribute(tuple, "media-right-margin", IPP_TAG_INTEGER);
@@ -1245,16 +1258,6 @@ int get_all_media(PrinterCUPS *p, Media **medias)
12451258
attr = ippFindAttribute(tuple, "media-bottom-margin", IPP_TAG_INTEGER);
12461259
margin->bottom = ippGetInteger(attr, 0);
12471260

1248-
attr = ippFindAttribute(tuple, "media-size", IPP_TAG_BEGIN_COLLECTION);
1249-
media_size = ippGetCollection(attr, 0);
1250-
attr = ippFindAttribute(media_size, "x-dimension", IPP_TAG_INTEGER);
1251-
width = ippGetInteger(attr, 0);
1252-
attr = ippFindAttribute(media_size, "y-dimension", IPP_TAG_INTEGER);
1253-
length = ippGetInteger(attr, 0);
1254-
1255-
pwg_media = pwgMediaForSize(width, length);
1256-
name = pwg_media->pwg;
1257-
12581261
margins = g_hash_table_lookup(table, name);
12591262
margins = g_list_prepend(margins, margin);
12601263
g_hash_table_replace(table, (gpointer) name, margins);

0 commit comments

Comments
 (0)