- else{
- fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
- return NULL;
+
+ pos = offset;
+ assert(pos >= 0);
+ assert((OPJ_OFF_T)length >= 0);
+ while (pos < offset + (OPJ_OFF_T)length - 7) { /* LBox+TBox-1=7*/
+
+ /* read LBox and TBox*/
+ if ((data = fetch_bytes(fd, pos, 8))) {
+ headlen = 8;
+ boxlen = (Byte8_t)big4(data);
+ boxtype = (char *)(data + 4);
+
+ if (boxlen == 1) {
+ Byte_t *data2;
+ headlen = 16;
+ /* read XLBox*/
+ if ((data2 = fetch_bytes(fd, pos + 8, 8))) {
+ boxlen = big8(data2);
+ free(data2);
+ } else {
+ fprintf(FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64
+ ", %s)\n", fd, offset, length, TBox);
+ return NULL;
+ }
+ }
+ if (strncmp(boxtype, TBox, 4) == 0) {
+ foundbox = (box_param_t *)malloc(sizeof(box_param_t));
+ foundbox->fd = fd;
+ foundbox->offset = pos;
+ foundbox->headlen = headlen;
+ foundbox->length = boxlen;
+ strncpy(foundbox->type, TBox, 4);
+ foundbox->next = NULL;
+ free(data);
+ return foundbox;
+ }
+ free(data);
+ } else {
+ fprintf(FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64
+ ", %s)\n", fd, offset, length, TBox);
+ return NULL;
+ }
+ assert(((Byte8_t)pos + boxlen) >= (Byte8_t)pos);
+ pos += (OPJ_OFF_T)boxlen;