Skip to content

Commit 682113c

Browse files
authored
fix: Safer context handling in streams (#170)
* fix: 1 * fix: Update c2pa.py code * fix: Renamings * fix: Format
1 parent 2740beb commit 682113c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/c2pa/c2pa.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,14 @@ def flush_callback(ctx):
11071107
self._write_cb = WriteCallback(write_callback)
11081108
self._flush_cb = FlushCallback(flush_callback)
11091109

1110+
# Create a placeholder context as we don't actually use the context,
1111+
# but we need having a valid context pointer. Therefore, we create
1112+
# a small buffer and cast it to a StreamContext pointer
1113+
self._context = ctypes.create_string_buffer(1)
1114+
11101115
# Create the stream
11111116
self._stream = _lib.c2pa_create_stream(
1112-
None, # context
1117+
ctypes.cast(self._context, ctypes.POINTER(StreamContext)),
11131118
self._read_cb,
11141119
self._seek_cb,
11151120
self._write_cb,

0 commit comments

Comments
 (0)