Commit bef2c2222a0b9429276b34d8f5024f31b8e86495
1 parent
73d70902
C API: qpdf_get_last_string_length
Showing
6 changed files
with
57 additions
and
12 deletions
ChangeLog
| 1 | +2021-12-02 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * C API: Add qpdf_get_last_string_length to return the length of | |
| 4 | + the last string returned. This is necessary in order to fully | |
| 5 | + retrieve values of strings that may contain embedded null characters. | |
| 6 | + | |
| 1 | 7 | 2021-11-16 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | |
| 3 | 9 | * 10.4.0: release | ... | ... |
TODO
include/qpdf/qpdf-c.h
| ... | ... | @@ -49,14 +49,17 @@ |
| 49 | 49 | * itself, is managed by the library. You must create a qpdf_data |
| 50 | 50 | * object using qpdf_init and free it using qpdf_cleanup. |
| 51 | 51 | * |
| 52 | - * Many functions return char*. In all cases, the char* values | |
| 53 | - * returned are pointers to data inside the qpdf_data object. As | |
| 54 | - * such, they are always freed by qpdf_cleanup. In most cases, | |
| 52 | + * Many functions return char*. In all cases, the char* values | |
| 53 | + * returned are pointers to data inside the qpdf_data object. As | |
| 54 | + * such, they are always freed by qpdf_cleanup. In most cases, | |
| 55 | 55 | * strings returned by functions here may be invalidated by |
| 56 | 56 | * subsequent function calls, sometimes even to different |
| 57 | - * functions. If you want a string to last past the next qpdf | |
| 58 | - * call or after a call to qpdf_cleanup, you should make a copy of | |
| 59 | - * it. | |
| 57 | + * functions. If you want a string to last past the next qpdf call | |
| 58 | + * or after a call to qpdf_cleanup, you should make a copy of it. | |
| 59 | + * It is possible for the internal string data to contain null | |
| 60 | + * characters. To handle that case, you call | |
| 61 | + * qpdf_get_last_string_length() to get the length of whatever | |
| 62 | + * string was just returned. | |
| 60 | 63 | * |
| 61 | 64 | * Many functions defined here merely set parameters and therefore |
| 62 | 65 | * never return error conditions. Functions that may cause PDF |
| ... | ... | @@ -126,6 +129,14 @@ extern "C" { |
| 126 | 129 | QPDF_DLL |
| 127 | 130 | void qpdf_cleanup(qpdf_data* qpdf); |
| 128 | 131 | |
| 132 | + /* Return the length of the last string returned. This enables you | |
| 133 | + * to retrieve the entire string for cases in which a char* | |
| 134 | + * returned by one of the functions below points to a string with | |
| 135 | + * embedded null characters. | |
| 136 | + */ | |
| 137 | + QPDF_DLL | |
| 138 | + size_t qpdf_get_last_string_length(qpdf_data qpdf); | |
| 139 | + | |
| 129 | 140 | /* ERROR REPORTING */ |
| 130 | 141 | |
| 131 | 142 | /* Returns 1 if there is an error condition. The error condition | ... | ... |
libqpdf/qpdf-c.cc
| ... | ... | @@ -172,6 +172,11 @@ void qpdf_cleanup(qpdf_data* qpdf) |
| 172 | 172 | *qpdf = 0; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | +size_t qpdf_get_last_string_length(qpdf_data qpdf) | |
| 176 | +{ | |
| 177 | + return qpdf->tmp_string.length(); | |
| 178 | +} | |
| 179 | + | |
| 175 | 180 | QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf) |
| 176 | 181 | { |
| 177 | 182 | QTC::TC("qpdf", "qpdf-c called qpdf_more_warnings"); | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -5117,6 +5117,28 @@ print "\n"; |
| 5117 | 5117 | </varlistentry> |
| 5118 | 5118 | --> |
| 5119 | 5119 | <varlistentry> |
| 5120 | + <term>10.5.0: XXX Month dd, YYYY</term> | |
| 5121 | + <listitem> | |
| 5122 | + <itemizedlist> | |
| 5123 | + <listitem> | |
| 5124 | + <para> | |
| 5125 | + Library Enhancements | |
| 5126 | + </para> | |
| 5127 | + <itemizedlist> | |
| 5128 | + <listitem> | |
| 5129 | + <para> | |
| 5130 | + Add <function>qpdf_get_last_string_length</function> to the | |
| 5131 | + C API to get the length of the last string that was | |
| 5132 | + returned. This is needed to handle strings that contain | |
| 5133 | + embedded null characters. | |
| 5134 | + </para> | |
| 5135 | + </listitem> | |
| 5136 | + </itemizedlist> | |
| 5137 | + </listitem> | |
| 5138 | + </itemizedlist> | |
| 5139 | + </listitem> | |
| 5140 | + </varlistentry> | |
| 5141 | + <varlistentry> | |
| 5120 | 5142 | <term>10.4.0: November 16, 2021</term> |
| 5121 | 5143 | <listitem> |
| 5122 | 5144 | <itemizedlist> | ... | ... |
qpdf/qpdf-ctest.c
| ... | ... | @@ -613,6 +613,13 @@ static void test24(char const* infile, |
| 613 | 613 | (strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) && |
| 614 | 614 | (strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) && |
| 615 | 615 | (strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0)); |
| 616 | + qpdf_oh p_string_with_null = qpdf_oh_parse(qpdf, "<6f6e650074776f>"); | |
| 617 | + assert(qpdf_oh_is_string(qpdf, p_string_with_null) && | |
| 618 | + (strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), | |
| 619 | + "one") == 0) && | |
| 620 | + (qpdf_get_last_string_length(qpdf) == 7) && | |
| 621 | + (memcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), | |
| 622 | + "one\000two", 7) == 0)); | |
| 616 | 623 | assert(qpdf_oh_is_dictionary(qpdf, p_dict)); |
| 617 | 624 | qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four"); |
| 618 | 625 | assert(qpdf_oh_is_or_has_name(qpdf, p_five, "/Five")); | ... | ... |