@@ -109,7 +109,6 @@ test_json_struct_metadata_get_blob(void)
109109 tsk_size_t metadata_length ;
110110 size_t header_length ;
111111 size_t json_length ;
112- size_t padding_length ;
113112 size_t payload_length ;
114113 size_t total_length ;
115114 char json_payload [] = "{\"a\":1}" ;
@@ -119,9 +118,8 @@ test_json_struct_metadata_get_blob(void)
119118 bytes = (uint8_t * ) metadata ;
120119 header_length = 4 + 1 + 8 + 8 ;
121120 json_length = strlen (json_payload );
122- padding_length = (8 - ((header_length + json_length ) & 0x07 )) % 8 ;
123121 payload_length = sizeof (binary_payload );
124- total_length = header_length + json_length + padding_length + payload_length ;
122+ total_length = header_length + json_length + payload_length ;
125123 CU_ASSERT_FATAL (total_length <= sizeof (metadata ));
126124 memset (metadata , 0 , sizeof (metadata ));
127125 bytes [0 ] = 'J' ;
@@ -132,64 +130,54 @@ test_json_struct_metadata_get_blob(void)
132130 set_u64_le (bytes + 5 , (uint64_t ) json_length );
133131 set_u64_le (bytes + 13 , (uint64_t ) payload_length );
134132 memcpy (bytes + header_length , json_payload , json_length );
135- memset (bytes + header_length + json_length , 0 , padding_length );
136- memcpy (bytes + header_length + json_length + padding_length , binary_payload ,
137- payload_length );
133+ memcpy (bytes + header_length + json_length , binary_payload , payload_length );
138134 metadata_length = (tsk_size_t ) total_length ;
139135 ret = tsk_json_struct_metadata_get_blob (
140136 metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
141137 CU_ASSERT_EQUAL (ret , 0 );
142138 CU_ASSERT_PTR_EQUAL (json , (char * ) bytes + header_length );
143- CU_ASSERT_EQUAL (json + json_buffer_length + padding_length , blob );
144139 CU_ASSERT_EQUAL (json_buffer_length , (tsk_size_t ) json_length );
145140 if (json_length > 0 ) {
146141 CU_ASSERT_EQUAL (memcmp (json , json_payload , json_length ), 0 );
147142 }
148- CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length + padding_length );
143+ CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length );
149144 CU_ASSERT_EQUAL (blob_length , (tsk_size_t ) payload_length );
150145 CU_ASSERT_EQUAL (memcmp (blob , binary_payload , payload_length ), 0 );
151- CU_ASSERT ((tsk_size_t ) (blob - json ) < json_buffer_length + 8 );
152146
153147 payload_length = 0 ;
154- total_length = header_length + json_length + padding_length + payload_length ;
148+ total_length = header_length + json_length + payload_length ;
155149 CU_ASSERT_FATAL (total_length <= sizeof (metadata ));
156150 set_u64_le (bytes + 13 , (uint64_t ) payload_length );
157151 metadata_length = (tsk_size_t ) total_length ;
158152 ret = tsk_json_struct_metadata_get_blob (
159153 metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
160154 CU_ASSERT_EQUAL (ret , 0 );
161- CU_ASSERT_EQUAL (json + json_buffer_length + padding_length , blob );
162155 CU_ASSERT_PTR_EQUAL (json , (char * ) bytes + header_length );
163156 CU_ASSERT_EQUAL (json_buffer_length , (tsk_size_t ) json_length );
164157 CU_ASSERT_EQUAL (blob_length , (tsk_size_t ) payload_length );
165- CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length + padding_length );
166- CU_ASSERT ((tsk_size_t ) (blob - json ) < json_buffer_length + 8 );
158+ CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length );
167159
168160 json_length = 0 ;
169161 payload_length = sizeof (empty_payload );
170- padding_length = (8 - ((header_length + json_length ) & 0x07 )) % 8 ;
171- total_length = header_length + json_length + padding_length + payload_length ;
162+ total_length = header_length + json_length + payload_length ;
172163 CU_ASSERT_FATAL (total_length <= sizeof (metadata ));
173164 set_u64_le (bytes + 5 , (uint64_t ) json_length );
174165 set_u64_le (bytes + 13 , (uint64_t ) payload_length );
175- memset (bytes + header_length + json_length , 0 , padding_length );
176- memcpy (bytes + header_length + json_length + padding_length , empty_payload ,
177- payload_length );
166+ memcpy (bytes + header_length + json_length , empty_payload , payload_length );
178167 metadata_length = (tsk_size_t ) total_length ;
179168 ret = tsk_json_struct_metadata_get_blob (
180169 metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
181170 CU_ASSERT_EQUAL (ret , 0 );
182171 CU_ASSERT_PTR_EQUAL (json , (char * ) bytes + header_length );
183172 CU_ASSERT_EQUAL (json_buffer_length , (tsk_size_t ) json_length );
184173 CU_ASSERT_EQUAL (blob_length , (tsk_size_t ) payload_length );
185- CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length + padding_length );
174+ CU_ASSERT_PTR_EQUAL (blob , bytes + header_length + json_length );
186175 CU_ASSERT_EQUAL (memcmp (blob , empty_payload , payload_length ), 0 );
187- CU_ASSERT ((tsk_size_t ) (blob - json ) < json_buffer_length + 8 );
188176
189177 blob = NULL ;
190178 blob_length = 0 ;
191179 json = NULL ;
192- json_length = 0 ;
180+ json_buffer_length = 0 ;
193181 metadata_length = header_length - 1 ;
194182 ret = tsk_json_struct_metadata_get_blob (
195183 metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
@@ -208,19 +196,7 @@ test_json_struct_metadata_get_blob(void)
208196 CU_ASSERT_EQUAL (ret , TSK_ERR_JSON_STRUCT_METADATA_BAD_VERSION );
209197 bytes [4 ] = 1 ;
210198
211- set_u64_le (bytes + 5 , (uint64_t ) json_length + 9 );
212- ret = tsk_json_struct_metadata_get_blob (
213- metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
214- CU_ASSERT_EQUAL (ret , TSK_ERR_JSON_STRUCT_METADATA_UNEXPECTED_SIZE );
215- set_u64_le (bytes + 5 , (uint64_t ) json_length );
216-
217- bytes [header_length + 1 ] = 1 ;
218- ret = tsk_json_struct_metadata_get_blob (
219- metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
220- CU_ASSERT_EQUAL (ret , TSK_ERR_JSON_STRUCT_METADATA_NONZERO_PADDING );
221- bytes [header_length + 1 ] = 0 ;
222-
223- metadata_length = (tsk_size_t ) (header_length - 1 );
199+ metadata_length = (tsk_size_t ) (total_length - 1 );
224200 ret = tsk_json_struct_metadata_get_blob (
225201 metadata , metadata_length , & json , & json_buffer_length , & blob , & blob_length );
226202 CU_ASSERT_EQUAL (ret , TSK_ERR_JSON_STRUCT_METADATA_TRUNCATED );
0 commit comments