Skip to content

Commit 6fb70fa

Browse files
authored
matrixload: ensure sniff data is null-terminated (#4541)
As required by `g_strlcpy()`.
1 parent 125fff3 commit 6fb70fa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

libvips/foreign/matrixload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ vips_foreign_load_matrix_source_is_a_source(VipsSource *source)
429429

430430
if ((bytes_read = vips_source_sniff_at_most(source, &data, 79)) <= 0)
431431
return FALSE;
432-
g_strlcpy(line, (const char *) data, 80);
432+
data[bytes_read] = '\0';
433+
g_strlcpy(line, (const char *) data, sizeof(line));
433434

434435
vips_error_freeze();
435436
result = parse_matrix_header(line, &width, &height, &scale, &offset);

test/test-suite/test_connection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ def test_connection_matrix(self):
102102

103103
assert (im - self.mono).abs().max() == 0
104104

105+
@skip_if_no("svgload_source")
106+
def test_connection_svg(self):
107+
svg = b'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" />'
108+
x = pyvips.Source.new_from_memory(svg)
109+
im = pyvips.Image.new_from_source(x, "")
110+
111+
assert im.width == 1
112+
assert im.height == 1
113+
105114
def test_connection_csv(self):
106115
x = pyvips.Target.new_to_memory()
107116
self.mono.csvsave_target(x)

0 commit comments

Comments
 (0)