2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
27 #include <atalk/errchk.h>
28 #include <atalk/util.h>
29 #include <atalk/logger.h>
30 #include <atalk/talloc.h>
31 #include <atalk/dalloc.h>
32 #include <atalk/byteorder.h>
33 #include <atalk/netatalk_conf.h>
34 #include <atalk/volume.h>
35 #include <atalk/dsi.h>
36 #include <atalk/spotlight.h>
38 #define MAX_SLQ_DAT (DSI_DATASIZ - 64)
39 #define MAX_SLQ_TOC 8192
41 /**************************************************************************************************
42 * RPC data marshalling and unmarshalling
43 **************************************************************************************************/
45 /* Spotlight epoch is UNIX epoch minus SPOTLIGHT_TIME_DELTA */
46 #define SPOTLIGHT_TIME_DELTA INT64_C(280878921600U)
48 #define SQ_TYPE_NULL 0x0000
49 #define SQ_TYPE_COMPLEX 0x0200
50 #define SQ_TYPE_INT64 0x8400
51 #define SQ_TYPE_BOOL 0x0100
52 #define SQ_TYPE_FLOAT 0x8500
53 #define SQ_TYPE_DATA 0x0700
54 #define SQ_TYPE_CNIDS 0x8700
55 #define SQ_TYPE_UUID 0x0e00
56 #define SQ_TYPE_DATE 0x8600
57 #define SQ_TYPE_TOC 0x8800
59 #define SQ_CPX_TYPE_ARRAY 0x0a00
60 #define SQ_CPX_TYPE_STRING 0x0c00
61 #define SQ_CPX_TYPE_UTF16_STRING 0x1c00
62 #define SQ_CPX_TYPE_DICT 0x0d00
63 #define SQ_CPX_TYPE_CNIDS 0x1a00
64 #define SQ_CPX_TYPE_FILEMETA 0x1b00
66 #define SUBQ_SAFETY_LIM 20
68 /* Forward declarations */
69 static int sl_pack_loop(DALLOC_CTX *query, char *buf, int offset, char *toc_buf, int *toc_idx);
70 static int sl_unpack_loop(DALLOC_CTX *query, const char *buf, int offset, uint count, const uint toc_offset, const uint encoding);
72 /**************************************************************************************************
73 * Wrapper functions for the *VAL macros with bound checking
74 **************************************************************************************************/
76 static int sivalc(char *buf, off_t off, off_t maxoff, uint32_t val)
78 if (off + sizeof(val) >= maxoff) {
79 LOG(log_error, logtype_sl, "sivalc: off: %zd, maxoff: %zd", off, maxoff);
86 static int slvalc(char *buf, off_t off, off_t maxoff, uint64_t val)
88 if (off + sizeof(val) >= maxoff) {
89 LOG(log_error, logtype_sl, "slvalc: off: %zd, maxoff: %zd", off, maxoff);
97 * Returns the UTF-16 string encoding, by checking the 2-byte byte order mark.
98 * If there is no byte order mark, -1 is returned.
100 static uint spotlight_get_utf16_string_encoding(const char *buf, int offset, int query_length, uint encoding) {
103 /* Assumed encoding in absence of a bom is little endian */
104 utf16_encoding = SL_ENC_LITTLE_ENDIAN;
106 if (query_length >= 2) {
107 uint8_t le_bom[] = {0xff, 0xfe};
108 uint8_t be_bom[] = {0xfe, 0xff};
109 if (memcmp(le_bom, buf + offset, sizeof(uint16_t)) == 0)
110 utf16_encoding = SL_ENC_LITTLE_ENDIAN | SL_ENC_UTF_16;
111 else if (memcmp(be_bom, buf + offset, sizeof(uint16_t)) == 0)
112 utf16_encoding = SL_ENC_BIG_ENDIAN | SL_ENC_UTF_16;
115 return utf16_encoding;
118 /**************************************************************************************************
119 * marshalling functions
120 **************************************************************************************************/
122 #define SL_OFFSET_DELTA 16
124 static uint64_t sl_pack_tag(uint16_t type, uint16_t size_or_count, uint32_t val)
126 uint64_t tag = ((uint64_t)val << 32) | ((uint64_t)type << 16) | size_or_count;
130 static int sl_pack_float(double d, char *buf, int offset)
139 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_FLOAT, 2, 1)) );
140 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, ieee_fp_union.w) );
145 return offset + 2 * sizeof(uint64_t);
148 static int sl_pack_uint64(uint64_t u, char *buf, int offset)
152 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_INT64, 2, 1)) );
153 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, u) );
158 return offset + 2 * sizeof(uint64_t);
161 static int sl_pack_bool(sl_bool_t bl, char *buf, int offset)
165 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_BOOL, 1, bl ? 1 : 0)) );
170 return offset + sizeof(uint64_t);
173 static int sl_pack_nil(char *buf, int offset)
177 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_NULL, 1, 1)) );
182 return offset + sizeof(uint64_t);
185 static int sl_pack_date(sl_time_t t, char *buf, int offset)
190 data = (t.tv_sec + SPOTLIGHT_TIME_DELTA) << 24;
192 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATE, 2, 1)) );
193 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, data) );
198 return offset + 2 * sizeof(uint64_t);
201 static int sl_pack_uuid(sl_uuid_t *uuid, char *buf, int offset)
205 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_UUID, 3, 1)) );
206 if (offset + 8 + 16 >= MAX_SLQ_DAT)
208 memcpy(buf + offset + 8, uuid, 16);
213 return offset + sizeof(uint64_t) + 16;
216 static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf, int *toc_idx)
220 int cnid_count = talloc_array_length(cnids->ca_cnids->dd_talloc_array);
223 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_CNIDS, (offset + SL_OFFSET_DELTA) / 8, 0)) );
224 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
228 len = cnid_count + 1;
232 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_CNIDS, len, 8 /* unknown meaning, but always 8 */)) );
235 if (cnid_count > 0) {
236 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(cnids->ca_unkn1, cnid_count, cnids->ca_context)) );
239 for (int i = 0; i < cnid_count; i++) {
240 memcpy(&id, cnids->ca_cnids->dd_talloc_array[i], sizeof(uint64_t));
241 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, id) );
252 static int sl_pack_array(sl_array_t *array, char *buf, int offset, char *toc_buf, int *toc_idx)
255 int count = talloc_array_length(array->dd_talloc_array);
256 int octets = (offset + SL_OFFSET_DELTA) / 8;
258 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_ARRAY, octets, count)) );
259 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
263 EC_NEG1( offset = sl_pack_loop(array, buf, offset, toc_buf, toc_idx) );
271 static int sl_pack_dict(sl_array_t *dict, char *buf, int offset, char *toc_buf, int *toc_idx)
275 EC_ZERO( slvalc(toc_buf,
278 sl_pack_tag(SQ_CPX_TYPE_DICT,
279 (offset + SL_OFFSET_DELTA) / 8,
280 talloc_array_length(dict->dd_talloc_array))) );
281 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
285 EC_NEG1( offset = sl_pack_loop(dict, buf, offset, toc_buf, toc_idx) );
293 static int sl_pack_filemeta(sl_filemeta_t *fm, char *buf, int offset, char *toc_buf, int *toc_idx)
296 int fmlen; /* lenght of filemeta */
297 int saveoff = offset;
299 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
302 EC_NEG1( fmlen = sl_pack(fm, buf + offset) );
304 /* Check for empty filemeta array, if it's only 40 bytes, it's only the header but no content */
305 LOG(log_debug, logtype_sl, "fmlen: %d", fmlen);
311 EC_ZERO( slvalc(buf, saveoff + 8, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATA, (fmlen / 8) + 1, 8 /* unknown meaning, but always 8 */)) );
313 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_FILEMETA, (saveoff + SL_OFFSET_DELTA) / 8, fmlen / 8)) );
322 static int sl_pack_string(char *s, char *buf, int offset, char *toc_buf, int *toc_idx)
325 int len, octets, used_in_last_octet;
328 octets = (len / 8) + (len & 7 ? 1 : 0);
329 used_in_last_octet = 8 - (octets * 8 - len);
331 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_STRING, (offset + SL_OFFSET_DELTA) / 8, used_in_last_octet)) );
332 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
336 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATA, octets + 1, used_in_last_octet)) );
339 if (offset + octets * 8 > MAX_SLQ_DAT)
341 memset(buf + offset, 0, octets * 8);
342 strncpy(buf + offset, s, len);
343 offset += octets * 8;
351 static int sl_pack_loop(DALLOC_CTX *query, char *buf, int offset, char *toc_buf, int *toc_idx)
356 for (int n = 0; n < talloc_array_length(query->dd_talloc_array); n++) {
358 type = talloc_get_name(query->dd_talloc_array[n]);
360 if (STRCMP(type, ==, "sl_array_t")) {
361 EC_NEG1( offset = sl_pack_array(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
362 } else if (STRCMP(type, ==, "sl_dict_t")) {
363 EC_NEG1( offset = sl_pack_dict(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
364 } else if (STRCMP(type, ==, "sl_filemeta_t")) {
365 EC_NEG1( offset = sl_pack_filemeta(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
366 } else if (STRCMP(type, ==, "uint64_t")) {
368 memcpy(&i, query->dd_talloc_array[n], sizeof(uint64_t));
369 EC_NEG1( offset = sl_pack_uint64(i, buf, offset) );
370 } else if (STRCMP(type, ==, "char *")) {
371 EC_NEG1( offset = sl_pack_string(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
372 } else if (STRCMP(type, ==, "sl_bool_t")) {
374 memcpy(&bl, query->dd_talloc_array[n], sizeof(sl_bool_t));
375 EC_NEG1( offset = sl_pack_bool(bl, buf, offset) );
376 } else if (STRCMP(type, ==, "double")) {
378 memcpy(&d, query->dd_talloc_array[n], sizeof(double));
379 EC_NEG1( offset = sl_pack_float(d, buf, offset) );
380 } else if (STRCMP(type, ==, "sl_nil_t")) {
381 EC_NEG1( offset = sl_pack_nil(buf, offset) );
382 } else if (STRCMP(type, ==, "sl_time_t")) {
384 memcpy(&t, query->dd_talloc_array[n], sizeof(sl_time_t));
385 EC_NEG1( offset = sl_pack_date(t, buf, offset) );
386 } else if (STRCMP(type, ==, "sl_uuid_t")) {
387 EC_NEG1( offset = sl_pack_uuid(query->dd_talloc_array[n], buf, offset) );
388 } else if (STRCMP(type, ==, "sl_cnids_t")) {
389 EC_NEG1( offset = sl_pack_CNID(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
399 /**************************************************************************************************
400 * unmarshalling functions
401 **************************************************************************************************/
403 static uint64_t sl_unpack_uint64(const char *buf, int offset, uint encoding)
405 if (encoding == SL_ENC_LITTLE_ENDIAN)
406 return LVAL(buf, offset);
408 return RLVAL(buf, offset);
411 static int sl_unpack_ints(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
414 uint64_t query_data64;
416 query_data64 = sl_unpack_uint64(buf, offset, encoding);
417 count = query_data64 >> 32;
421 while (i++ < count) {
422 query_data64 = sl_unpack_uint64(buf, offset, encoding);
423 dalloc_add_copy(query, &query_data64, uint64_t);
430 static int sl_unpack_date(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
433 uint64_t query_data64;
436 query_data64 = sl_unpack_uint64(buf, offset, encoding);
437 count = query_data64 >> 32;
441 while (i++ < count) {
442 query_data64 = sl_unpack_uint64(buf, offset, encoding) >> 24;
443 t.tv_sec = query_data64 - SPOTLIGHT_TIME_DELTA;
445 dalloc_add_copy(query, &t, sl_time_t);
452 static int sl_unpack_uuid(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
455 uint64_t query_data64;
457 query_data64 = sl_unpack_uint64(buf, offset, encoding);
458 count = query_data64 >> 32;
462 while (i++ < count) {
463 memcpy(uuid.sl_uuid, buf + offset, 16);
464 dalloc_add_copy(query, &uuid, sl_uuid_t);
471 static int sl_unpack_floats(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
474 uint64_t query_data64;
480 query_data64 = sl_unpack_uint64(buf, offset, encoding);
481 count = query_data64 >> 32;
485 while (i++ < count) {
486 if (encoding == SL_ENC_LITTLE_ENDIAN) {
487 #ifdef WORDS_BIGENDIAN
488 ieee_fp_union.w[0] = IVAL(buf, offset + 4);
489 ieee_fp_union.w[1] = IVAL(buf, offset);
491 ieee_fp_union.w[0] = IVAL(buf, offset);
492 ieee_fp_union.w[1] = IVAL(buf, offset + 4);
495 #ifdef WORDS_BIGENDIAN
496 ieee_fp_union.w[0] = RIVAL(buf, offset);
497 ieee_fp_union.w[1] = RIVAL(buf, offset + 4);
499 ieee_fp_union.w[0] = RIVAL(buf, offset + 4);
500 ieee_fp_union.w[1] = RIVAL(buf, offset);
503 dalloc_add_copy(query, &ieee_fp_union.d, double);
510 static int sl_unpack_CNID(DALLOC_CTX *query, const char *buf, int offset, int length, uint encoding)
514 uint64_t query_data64;
517 EC_NULL( cnids = talloc_zero(query, sl_cnids_t) );
518 EC_NULL( cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX) );
521 /* that's permitted, it's an empty array */
524 query_data64 = sl_unpack_uint64(buf, offset, encoding);
525 count = query_data64 & 0xffff;
527 cnids->ca_unkn1 = (query_data64 & 0xffff0000) >> 16;
528 cnids->ca_context = query_data64 >> 32;
533 query_data64 = sl_unpack_uint64(buf, offset, encoding);
534 dalloc_add_copy(cnids->ca_cnids, &query_data64, uint64_t);
538 dalloc_add(query, cnids, sl_cnids_t);
544 static const char *spotlight_get_qtype_string(uint64_t query_type)
546 switch (query_type) {
549 case SQ_TYPE_COMPLEX:
566 static const char *spotlight_get_cpx_qtype_string(uint64_t cpx_query_type)
568 switch (cpx_query_type) {
569 case SQ_CPX_TYPE_ARRAY:
571 case SQ_CPX_TYPE_STRING:
573 case SQ_CPX_TYPE_UTF16_STRING:
574 return "utf-16 string";
575 case SQ_CPX_TYPE_DICT:
577 case SQ_CPX_TYPE_CNIDS:
579 case SQ_CPX_TYPE_FILEMETA:
586 static int sl_unpack_cpx(DALLOC_CTX *query,
590 uint cpx_query_count,
591 const uint toc_offset,
596 int roffset = offset;
597 uint64_t query_data64;
598 uint unicode_encoding;
601 int qlen, used_in_last_block, slen;
602 sl_array_t *sl_array;
604 sl_filemeta_t *sl_fm;
606 switch (cpx_query_type) {
607 case SQ_CPX_TYPE_ARRAY:
608 sl_array = talloc_zero(query, sl_array_t);
609 EC_NEG1_LOG( roffset = sl_unpack_loop(sl_array, buf, offset, cpx_query_count, toc_offset, encoding) );
610 dalloc_add(query, sl_array, sl_array_t);
613 case SQ_CPX_TYPE_DICT:
614 sl_dict = talloc_zero(query, sl_dict_t);
615 EC_NEG1_LOG( roffset = sl_unpack_loop(sl_dict, buf, offset, cpx_query_count, toc_offset, encoding) );
616 dalloc_add(query, sl_dict, sl_dict_t);
619 case SQ_CPX_TYPE_STRING:
620 case SQ_CPX_TYPE_UTF16_STRING:
621 query_data64 = sl_unpack_uint64(buf, offset, encoding);
622 qlen = (query_data64 & 0xffff) * 8;
623 used_in_last_block = query_data64 >> 32;
624 slen = qlen - 16 + used_in_last_block;
626 if (cpx_query_type == SQ_CPX_TYPE_STRING) {
627 p = dalloc_strndup(query, buf + offset + 8, slen);
629 unicode_encoding = spotlight_get_utf16_string_encoding(buf, offset + 8, slen, encoding);
630 mark_exists = (unicode_encoding & SL_ENC_UTF_16);
631 if (unicode_encoding & SL_ENC_BIG_ENDIAN)
632 EC_FAIL_LOG("Unsupported big endian UTF16 string");
633 slen -= mark_exists ? 2 : 0;
634 EC_NEG1( convert_string_allocate(CH_UCS2,
636 buf + offset + (mark_exists ? 10 : 8),
639 p = dalloc_strndup(query, tmp, strlen(tmp));
643 dalloc_add(query, p, char *);
647 case SQ_CPX_TYPE_FILEMETA:
648 query_data64 = sl_unpack_uint64(buf, offset, encoding);
649 qlen = (query_data64 & 0xffff) * 8;
651 EC_FAIL_LOG("SQ_CPX_TYPE_FILEMETA: query_length <= 8: %d", qlen);
653 sl_fm = talloc_zero(query, sl_filemeta_t);
654 EC_NEG1_LOG( sl_unpack(sl_fm, buf + offset + 8) );
655 dalloc_add(query, sl_fm, sl_filemeta_t);
660 case SQ_CPX_TYPE_CNIDS:
661 query_data64 = sl_unpack_uint64(buf, offset, encoding);
662 qlen = (query_data64 & 0xffff) * 8;
663 EC_NEG1_LOG( sl_unpack_CNID(query, buf, offset + 8, qlen, encoding) );
677 static int sl_unpack_loop(DALLOC_CTX *query,
681 const uint toc_offset,
685 int i, toc_index, query_length;
687 uint64_t query_data64, query_type;
688 uint cpx_query_type, cpx_query_count;
692 while (count > 0 && (offset < toc_offset)) {
693 query_data64 = sl_unpack_uint64(buf, offset, encoding);
694 query_length = (query_data64 & 0xffff) * 8;
695 query_type = (query_data64 & 0xffff0000) >> 16;
696 if (query_length == 0)
699 switch (query_type) {
700 case SQ_TYPE_COMPLEX:
701 toc_index = (query_data64 >> 32) - 1;
702 query_data64 = sl_unpack_uint64(buf, toc_offset + toc_index * 8, encoding);
703 cpx_query_type = (query_data64 & 0xffff0000) >> 16;
704 cpx_query_count = query_data64 >> 32;
706 EC_NEG1_LOG( offset = sl_unpack_cpx(query, buf, offset + 8, cpx_query_type, cpx_query_count, toc_offset, encoding));
710 subcount = query_data64 >> 32;
714 for (i = 0; i < subcount; i++)
715 dalloc_add_copy(query, &nil, sl_nil_t);
716 offset += query_length;
720 b = query_data64 >> 32;
721 dalloc_add_copy(query, &b, sl_bool_t);
722 offset += query_length;
726 EC_NEG1_LOG( subcount = sl_unpack_ints(query, buf, offset, encoding) );
727 offset += query_length;
731 EC_NEG1_LOG( subcount = sl_unpack_uuid(query, buf, offset, encoding) );
732 offset += query_length;
736 EC_NEG1_LOG( subcount = sl_unpack_floats(query, buf, offset, encoding) );
737 offset += query_length;
741 EC_NEG1_LOG( subcount = sl_unpack_date(query, buf, offset, encoding) );
742 offset += query_length;
757 /**************************************************************************************************
758 * Global functions for packing und unpacking
759 **************************************************************************************************/
761 int sl_pack(DALLOC_CTX *query, char *buf)
764 char toc_buf[MAX_SLQ_TOC];
768 memcpy(buf, "432130dm", 8);
769 EC_NEG1_LOG( len = sl_pack_loop(query, buf + 16, 0, toc_buf + 8, &toc_index) );
770 EC_ZERO( sivalc(buf, 8, MAX_SLQ_DAT, len / 8 + 1 + toc_index + 1) );
771 EC_ZERO( sivalc(buf, 12, MAX_SLQ_DAT, len / 8 + 1) );
773 EC_ZERO( slvalc(toc_buf, 0, MAX_SLQ_TOC, sl_pack_tag(SQ_TYPE_TOC, toc_index + 1, 0)) );
774 if ((16 + len + ((toc_index + 1 ) * 8)) >= MAX_SLQ_DAT)
776 memcpy(buf + 16 + len, toc_buf, (toc_index + 1 ) * 8);
777 len += 16 + (toc_index + 1 ) * 8;
785 int sl_unpack(DALLOC_CTX *query, const char *buf)
788 int encoding, toc_entries;
791 if (strncmp(buf, "md031234", 8) == 0)
792 encoding = SL_ENC_BIG_ENDIAN;
794 encoding = SL_ENC_LITTLE_ENDIAN;
798 toc_offset = ((sl_unpack_uint64(buf, 0, encoding) >> 32) - 1 ) * 8;
799 if (toc_offset < 0 || (toc_offset > 65000)) {
805 toc_entries = (int)(sl_unpack_uint64(buf, toc_offset, encoding) & 0xffff);
807 EC_NEG1( sl_unpack_loop(query, buf, 0, 1, toc_offset + 8, encoding) );