~ubuntu-branches/ubuntu/utopic/clamav/utopic-security

« back to all changes in this revision

Viewing changes to libclamav/unarj.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
 
142
142
typedef struct arj_decode_tag {
143
143
        unsigned char *text;
144
 
        int fd;
 
144
        fmap_t *map;
 
145
        size_t offset;
 
146
        const uint8_t *buf;
 
147
        const void *bufend;
145
148
        uint16_t blocksize;
146
149
        uint16_t bit_buf;
147
150
        int bit_count;
159
162
 
160
163
static int fill_buf(arj_decode_t *decode_data, int n)
161
164
{
 
165
        if (decode_data->status == CL_EFORMAT)
 
166
            return CL_EFORMAT;
162
167
        decode_data->bit_buf = (decode_data->bit_buf << n) & 0xFFFF;
163
168
        while (n > decode_data->bit_count) {
164
169
                decode_data->bit_buf |= decode_data->sub_bit_buf << (n -= decode_data->bit_count);
165
170
                if (decode_data->comp_size != 0) {
166
171
                        decode_data->comp_size--;
167
 
                        if (cli_readn(decode_data->fd, &decode_data->sub_bit_buf, 1) != 1) {
 
172
                        if (decode_data->buf == decode_data->bufend) {
 
173
                            size_t len;
 
174
                            decode_data->buf = fmap_need_off_once_len(decode_data->map, decode_data->offset, 8192, &len);
 
175
                            if (!decode_data->buf || !len) {
168
176
                                /* the file is most likely corrupted, so
169
177
                                 * we return CL_EFORMAT instead of CL_EREAD
170
178
                                 */
171
179
                                decode_data->status = CL_EFORMAT;
172
180
                                return CL_EFORMAT;
 
181
                            }
 
182
                            decode_data->bufend = decode_data->buf + len;
173
183
                        }
 
184
                        decode_data->sub_bit_buf = *decode_data->buf++;
 
185
                        decode_data->offset++;
174
186
                } else {
175
187
                        decode_data->sub_bit_buf = 0;
176
188
                }
529
541
        return j;
530
542
}
531
543
 
532
 
static int decode(int fd, arj_metadata_t *metadata)
 
544
static int decode(arj_metadata_t *metadata)
533
545
{
534
546
        int ret;
535
547
 
542
554
        if (!decode_data.text) {
543
555
                return CL_EMEM;
544
556
        }
545
 
        decode_data.fd = fd;
 
557
        decode_data.map = metadata->map;
 
558
        decode_data.offset = metadata->offset;
546
559
        decode_data.comp_size = metadata->comp_size;
547
560
        ret = decode_start(&decode_data);
548
561
        if (ret != CL_SUCCESS) {
549
562
                free(decode_data.text);
 
563
                metadata->offset = decode_data.offset;
550
564
                return ret;
551
565
        }
552
566
        decode_data.status = CL_SUCCESS;
559
573
                                out_ptr = 0;
560
574
                                if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
561
575
                                        free(decode_data.text);
 
576
                                        metadata->offset = decode_data.offset;
562
577
                                        return CL_EWRITE;
563
578
                                }
564
579
                        }
584
599
                                                out_ptr = 0;
585
600
                                                if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
586
601
                                                        free(decode_data.text);
 
602
                                                        metadata->offset = decode_data.offset;
587
603
                                                        return CL_EWRITE;
588
604
                                                }
589
605
                                        }
595
611
                }
596
612
                if (decode_data.status != CL_SUCCESS) {
597
613
                        free(decode_data.text);
 
614
                        metadata->offset = decode_data.offset;
598
615
                        return decode_data.status;
599
616
                }
600
617
        }
601
618
        if (out_ptr != 0) {
602
619
                write_text(metadata->ofd, decode_data.text, out_ptr);
603
620
        }
604
 
        
 
621
 
605
622
        free(decode_data.text);
 
623
        metadata->offset = decode_data.offset;
606
624
        return CL_SUCCESS;
607
625
}
608
626
 
653
671
        return c;
654
672
}
655
673
 
656
 
static int decode_f(int fd, arj_metadata_t *metadata)
 
674
static int decode_f(arj_metadata_t *metadata)
657
675
{
658
676
        int ret;
659
677
 
667
685
        if (!decode_data.text) {
668
686
                return CL_EMEM;
669
687
        }
670
 
        decode_data.fd = fd;
 
688
        decode_data.map = metadata->map;
 
689
        decode_data.offset = metadata->offset;
671
690
        decode_data.comp_size = metadata->comp_size;
672
691
        ret = init_getbits(&decode_data);
673
692
        if (ret != CL_SUCCESS) {
 
693
                metadata->offset = decode_data.offset;
674
694
                return ret;
675
695
        }
676
 
        decode_data.getlen = decode_data.getbuf = 0;
 
696
        decode_data.getlen = decode_data.getbuf = 0;
677
697
        decode_data.status = CL_SUCCESS;
678
 
        
 
698
 
679
699
        while (count < metadata->orig_size) {
680
700
                chr = decode_len(&decode_data);
681
701
                if (decode_data.status != CL_SUCCESS) {
682
702
                        free(decode_data.text);
 
703
                        metadata->offset = decode_data.offset;
683
704
                        return decode_data.status;
684
 
                }               
 
705
                }
685
706
                if (chr == 0) {
686
707
                        ARJ_GETBITS(dd, chr, CHAR_BIT);
687
708
                        if (decode_data.status != CL_SUCCESS) {
688
709
                                free(decode_data.text);
 
710
                                metadata->offset = decode_data.offset;
689
711
                                return decode_data.status;
690
712
                        }
691
713
                        decode_data.text[out_ptr] = (unsigned char) chr;
694
716
                                out_ptr = 0;
695
717
                                if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
696
718
                                        free(decode_data.text);
 
719
                                        metadata->offset = decode_data.offset;
697
720
                                        return CL_EWRITE;
698
721
                                }
699
722
                        }
703
726
                        pos = decode_ptr(&decode_data);
704
727
                        if (decode_data.status != CL_SUCCESS) {
705
728
                                free(decode_data.text);
 
729
                                metadata->offset = decode_data.offset;
706
730
                                return decode_data.status;
707
731
                        }
708
732
                        if ((i = out_ptr - pos - 1) < 0) {
718
742
                                        out_ptr = 0;
719
743
                                        if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
720
744
                                                free(decode_data.text);
 
745
                                                metadata->offset = decode_data.offset;
721
746
                                                return CL_EWRITE;
722
747
                                        }
723
748
                                }
730
755
        if (out_ptr != 0) {
731
756
                write_text(metadata->ofd, decode_data.text, out_ptr);
732
757
        }
733
 
        
 
758
 
734
759
        free(decode_data.text);
 
760
        metadata->offset = decode_data.offset;
735
761
        return CL_SUCCESS;
736
 
}       
 
762
}
737
763
 
738
 
static uint32_t arj_unstore(int ifd, int ofd, uint32_t len)
 
764
static int arj_unstore(arj_metadata_t *metadata, int ofd, uint32_t len)
739
765
{
740
 
        unsigned char data[8192];
741
 
        uint32_t count, rem;
 
766
        const unsigned char *data;
 
767
        uint32_t rem;
742
768
        unsigned int todo;
 
769
        size_t count;
743
770
 
744
771
        cli_dbgmsg("in arj_unstore\n");
745
772
        rem = len;
746
773
 
747
774
        while (rem > 0) {
748
775
                todo = (unsigned int) MIN(8192, rem);
749
 
                count = cli_readn(ifd, data, todo);
750
 
                if (count != todo) {
751
 
                        return len-rem;
752
 
                }
 
776
                data = fmap_need_off_once_len(metadata->map, metadata->offset, todo, &count);
 
777
                if (!data || !count) {
 
778
                        /* Truncated file, not enough bytes available */
 
779
                        return CL_EFORMAT;
 
780
                }
 
781
                metadata->offset += count;
753
782
                if (cli_writen(ofd, data, count) != count) {
754
 
                        return len-rem-count;
 
783
                        /* File writing problem */
 
784
                        return CL_EWRITE;
755
785
                }
756
786
                rem -= count;
757
787
        }
758
 
        return len;
 
788
        return CL_SUCCESS;
759
789
}
760
790
 
761
 
static int is_arj_archive(int fd)
 
791
static int is_arj_archive(arj_metadata_t *metadata)
762
792
{
763
793
        const char header_id[2] = {0x60, 0xea};
764
 
        char mark[2];
765
 
        
766
 
        if (cli_readn(fd, &mark[0], 2) != 2) {
767
 
                return FALSE;
768
 
        }
 
794
        const char *mark;
 
795
 
 
796
        mark = fmap_need_off_once(metadata->map, metadata->offset, 2);
 
797
        if (!mark)
 
798
            return FALSE;
 
799
        metadata->offset += 2;
769
800
        if (memcmp(&mark[0], &header_id[0], 2) == 0) {
770
801
                return TRUE;
771
802
        }
773
804
        return FALSE;
774
805
}
775
806
 
776
 
static int arj_read_main_header(int fd)
 
807
static int arj_read_main_header(arj_metadata_t *metadata)
777
808
{
778
809
        uint16_t header_size, count;
779
810
        uint32_t crc;
780
811
        arj_main_hdr_t main_hdr;
781
 
        char *filename, *comment;
 
812
        const char *filename, *comment;
782
813
        off_t header_offset;
783
814
 
784
 
        if (cli_readn(fd, &header_size, 2) != 2) {
785
 
                return FALSE;
786
 
        }
787
 
        header_offset = lseek(fd, 0, SEEK_CUR);
 
815
        if (fmap_readn(metadata->map, &header_size, metadata->offset, 2) != 2)
 
816
            return FALSE;
 
817
 
 
818
        metadata->offset += 2;
 
819
        header_offset = metadata->offset;
788
820
        header_size = le16_to_host(header_size);
789
821
        cli_dbgmsg("Header Size: %d\n", header_size);
790
822
        if (header_size == 0) {
795
827
                cli_dbgmsg("arj_read_header: invalid header_size: %u\n ", header_size);
796
828
                return FALSE;
797
829
        }
798
 
        
799
 
        if (cli_readn(fd, &main_hdr, 30) != 30) {
800
 
                return FALSE;
801
 
        }
802
 
        
 
830
        if (fmap_readn(metadata->map, &main_hdr, metadata->offset, 30) != 30)
 
831
            return FALSE;
 
832
        metadata->offset += 30;
 
833
 
803
834
        cli_dbgmsg("ARJ Main File Header\n");
804
835
        cli_dbgmsg("First Header Size: %d\n", main_hdr.first_hdr_size);
805
836
        cli_dbgmsg("Version: %d\n", main_hdr.version);
814
845
                return FALSE;
815
846
        }
816
847
        if (main_hdr.first_hdr_size > 30) {
817
 
                if (lseek(fd, main_hdr.first_hdr_size - 30, SEEK_CUR) == -1) {
818
 
                        return FALSE;
819
 
                }
 
848
            metadata->offset += main_hdr.first_hdr_size - 30;
820
849
        }
821
850
 
822
 
        filename = (char *) cli_malloc(header_size);
 
851
        filename = fmap_need_offstr(metadata->map, metadata->offset, header_size);
823
852
        if (!filename) {
824
 
                return FALSE;
825
 
        }
826
 
        for (count=0 ; count < header_size ; count++) {
827
 
                if (cli_readn(fd, &filename[count], 1) != 1) {
828
 
                        free(filename);
829
 
                        return FALSE;
830
 
                }
831
 
                if (filename[count] == '\0') {
832
 
                        break;
833
 
                }
834
 
        }
835
 
        if (count == header_size) {
836
 
                free(filename);
837
 
                return FALSE;
838
 
        }
839
 
        comment = (char *) cli_malloc(header_size);
 
853
        cli_dbgmsg("UNARJ: Unable to allocate memory for filename\n");
 
854
                return FALSE;
 
855
    }
 
856
        metadata->offset += strlen(filename) + 1;
 
857
 
 
858
        comment = fmap_need_offstr(metadata->map, metadata->offset, header_size);
840
859
        if (!comment) {
841
 
                free(filename);
842
 
                return FALSE;
843
 
        }
844
 
        for (count=0 ; count < header_size ; count++) {
845
 
                if (cli_readn(fd, &comment[count], 1) != 1) {
846
 
                        free(filename);
847
 
                        free(comment);
848
 
                        return FALSE;
849
 
                }
850
 
                if (comment[count] == '\0') {
851
 
                        break;
852
 
                }
853
 
        }
854
 
        if (count == header_size) {
855
 
                free(filename);
856
 
                free(comment);
857
 
                return FALSE;
858
 
        }
 
860
        cli_dbgmsg("UNARJ: Unable to allocate memory for comment\n");
 
861
                return FALSE;
 
862
    }
 
863
        metadata->offset += strlen(comment) + 1;
859
864
        cli_dbgmsg("Filename: %s\n", filename);
860
865
        cli_dbgmsg("Comment: %s\n", comment);
861
 
        
862
 
        free(filename);
863
 
        free(comment);
864
 
        
865
 
        if (cli_readn(fd, &crc, 4) != 4) {
866
 
                return FALSE;
867
 
        }
868
 
        
 
866
 
 
867
        metadata->offset += 4; /* crc */
869
868
        /* Skip past any extended header data */
870
869
        for (;;) {
871
 
                if (cli_readn(fd, &count, 2) != 2) {
 
870
                const uint16_t *countp = fmap_need_off_once(metadata->map, metadata->offset, 2);
 
871
                if (!countp)
872
872
                        return FALSE;
873
 
                }
874
 
                count = le16_to_host(count);
 
873
                count = cli_readint16(countp);
 
874
                metadata->offset += 2;
875
875
                cli_dbgmsg("Extended header size: %d\n", count);
876
876
                if (count == 0) {
877
877
                        break;
878
878
                }
879
879
                /* Skip extended header + 4byte CRC */
880
 
                if (lseek(fd, (off_t) (count + 4), SEEK_CUR) == -1) {
881
 
                        return FALSE;
882
 
                }
 
880
                metadata->offset += count + 4;
883
881
        }
884
882
        return TRUE;
885
883
}
886
884
 
887
 
static int arj_read_file_header(int fd, arj_metadata_t *metadata)
 
885
static int arj_read_file_header(arj_metadata_t *metadata)
888
886
{
889
887
        uint16_t header_size, count;
890
 
        char *filename, *comment;
 
888
        const char *filename, *comment;
891
889
        arj_file_hdr_t file_hdr;
892
 
        
893
 
        if (cli_readn(fd, &header_size, 2) != 2) {
894
 
                return CL_EFORMAT;
895
 
        }
 
890
 
 
891
        if (fmap_readn(metadata->map, &header_size, metadata->offset, 2) != 2)
 
892
            return CL_EFORMAT;
896
893
        header_size = le16_to_host(header_size);
 
894
        metadata->offset += 2;
 
895
 
897
896
        cli_dbgmsg("Header Size: %d\n", header_size);
898
897
        if (header_size == 0) {
899
898
                /* End of archive */
903
902
                cli_dbgmsg("arj_read_file_header: invalid header_size: %u\n ", header_size);
904
903
                return CL_EFORMAT;
905
904
        }
906
 
        
907
 
        if (cli_readn(fd, &file_hdr, 30) != 30) {
 
905
 
 
906
        if (fmap_readn(metadata->map, &file_hdr, metadata->offset, 30) != 30) {
908
907
                return CL_EFORMAT;
909
908
        }
 
909
        metadata->offset += 30;
910
910
        file_hdr.comp_size = le32_to_host(file_hdr.comp_size);
911
911
        file_hdr.orig_size = le32_to_host(file_hdr.orig_size);
912
 
        
 
912
 
913
913
        cli_dbgmsg("ARJ File Header\n");
914
914
        cli_dbgmsg("First Header Size: %d\n", file_hdr.first_hdr_size);
915
915
        cli_dbgmsg("Version: %d\n", file_hdr.version);
929
929
 
930
930
        /* Note: this skips past any extended file start position data (multi-volume) */
931
931
        if (file_hdr.first_hdr_size > 30) {
932
 
                if (lseek(fd, file_hdr.first_hdr_size - 30, SEEK_CUR) == -1) {
933
 
                        return CL_EFORMAT;
934
 
                }
 
932
            metadata->offset += file_hdr.first_hdr_size - 30;
935
933
        }
936
934
 
937
 
        filename = (char *) cli_malloc(header_size);
 
935
        filename = fmap_need_offstr(metadata->map, metadata->offset, header_size);
938
936
        if (!filename) {
939
 
                return CL_EMEM;
940
 
        }
941
 
        for (count=0 ; count < header_size ; count++) {
942
 
                if (cli_readn(fd, &filename[count], 1) != 1) {
943
 
                        free(filename);
944
 
                        return CL_EFORMAT;
945
 
                }
946
 
                if (filename[count] == '\0') {
947
 
                        break;
948
 
                }
949
 
        }
950
 
        if (count == header_size) {
951
 
                free(filename);
952
 
                return CL_EFORMAT;
953
 
        }
 
937
        cli_dbgmsg("UNARJ: Unable to allocate memory for filename\n");
 
938
                return FALSE;
 
939
    }
 
940
        metadata->offset += strlen(filename) + 1;
954
941
 
955
 
        comment = (char *) cli_malloc(header_size);
 
942
        comment = fmap_need_offstr(metadata->map, metadata->offset, header_size);
956
943
        if (!comment) {
957
 
                free(filename);
958
 
                return CL_EFORMAT;
959
 
        }
960
 
        for (count=0 ; count < header_size ; count++) {
961
 
                if (cli_readn(fd, &comment[count], 1) != 1) {
962
 
                        free(filename);
963
 
                        free(comment);
964
 
                        return CL_EFORMAT;
965
 
                }
966
 
                if (comment[count] == '\0') {
967
 
                        break;
968
 
                }
969
 
        }
970
 
        if (count == header_size) {
971
 
                free(filename);
972
 
                free(comment);
973
 
                return CL_EFORMAT;
974
 
        }
 
944
        cli_dbgmsg("UNARJ: Unable to allocate memory for comment\n");
 
945
                return FALSE;
 
946
    }
 
947
        metadata->offset += strlen(comment) + 1;
975
948
        cli_dbgmsg("Filename: %s\n", filename);
976
949
        cli_dbgmsg("Comment: %s\n", comment);
977
950
        metadata->filename = cli_strdup(filename);
978
951
 
979
 
        free(filename);
980
 
        free(comment);
981
 
 
982
952
        /* Skip CRC */
983
 
        if (lseek(fd, (off_t) 4, SEEK_CUR) == -1) {
984
 
                if(metadata->filename)
985
 
                    free(metadata->filename);
986
 
                metadata->filename = NULL;
987
 
                return CL_EFORMAT;
988
 
        }
989
 
        
 
953
        metadata->offset += 4;
 
954
 
990
955
        /* Skip past any extended header data */
991
956
        for (;;) {
992
 
                if (cli_readn(fd, &count, 2) != 2) {
 
957
                const uint16_t *countp = fmap_need_off_once(metadata->map, metadata->offset, 2);
 
958
                if (!countp) {
993
959
                        if(metadata->filename)
994
960
                            free(metadata->filename);
995
961
                        metadata->filename = NULL;
996
962
                        return CL_EFORMAT;
997
963
                }
998
 
                count = le16_to_host(count);
 
964
                count = cli_readint16(countp);
 
965
                metadata->offset += 2;
999
966
                cli_dbgmsg("Extended header size: %d\n", count);
1000
967
                if (count == 0) {
1001
968
                        break;
1002
969
                }
1003
970
                /* Skip extended header + 4byte CRC */
1004
 
                if (lseek(fd, (off_t) (count + 4), SEEK_CUR) == -1) {
1005
 
                        if(metadata->filename)
1006
 
                            free(metadata->filename);
1007
 
                        metadata->filename = NULL;
1008
 
                        return CL_EFORMAT;
1009
 
                }
 
971
                metadata->offset += count + 4;
1010
972
        }
1011
973
        metadata->comp_size = file_hdr.comp_size;
1012
974
        metadata->orig_size = file_hdr.orig_size;
1016
978
        if (!metadata->filename) {
1017
979
                return CL_EMEM;
1018
980
        }
1019
 
        
1020
 
        return CL_SUCCESS;
 
981
 
 
982
        return CL_SUCCESS;
1021
983
}
1022
984
 
1023
 
int cli_unarj_open(int fd, const char *dirname)
 
985
int cli_unarj_open(fmap_t *map, const char *dirname, arj_metadata_t *metadata, size_t off)
1024
986
{
1025
 
 
1026
987
        cli_dbgmsg("in cli_unarj_open\n");
1027
 
 
1028
 
        if (!is_arj_archive(fd)) {
 
988
        metadata->map = map;
 
989
        metadata->offset = off;
 
990
        if (!is_arj_archive(metadata)) {
1029
991
                cli_dbgmsg("Not in ARJ format\n");
1030
992
                return CL_EFORMAT;
1031
993
        }
1032
 
        if (!arj_read_main_header(fd)) {
 
994
        if (!arj_read_main_header(metadata)) {
1033
995
                cli_dbgmsg("Failed to read main header\n");
1034
996
                return CL_EFORMAT;
1035
997
        }
1036
998
        return CL_SUCCESS;
1037
999
}
1038
1000
 
1039
 
int cli_unarj_prepare_file(int fd, const char *dirname, arj_metadata_t *metadata)
 
1001
int cli_unarj_prepare_file(const char *dirname, arj_metadata_t *metadata)
1040
1002
{
1041
1003
        cli_dbgmsg("in cli_unarj_prepare_file\n");
1042
 
        if (!metadata || !dirname || (fd < 0)) {
 
1004
        if (!metadata || !dirname) {
1043
1005
                return CL_ENULLARG;
1044
1006
        }
1045
1007
        /* Each file is preceeded by the ARJ file marker */
1046
 
        if (!is_arj_archive(fd)) {
 
1008
        if (!is_arj_archive(metadata)) {
1047
1009
                cli_dbgmsg("Not in ARJ format\n");
1048
1010
                return CL_EFORMAT;
1049
1011
        }
1050
 
        return arj_read_file_header(fd, metadata);
 
1012
        return arj_read_file_header(metadata);
1051
1013
}
1052
1014
 
1053
 
int cli_unarj_extract_file(int fd, const char *dirname, arj_metadata_t *metadata)
 
1015
int cli_unarj_extract_file(const char *dirname, arj_metadata_t *metadata)
1054
1016
{
1055
1017
        off_t offset;
1056
1018
        int ret = CL_SUCCESS;
1057
1019
        char filename[1024];
1058
 
        
 
1020
 
1059
1021
        cli_dbgmsg("in cli_unarj_extract_file\n");
1060
 
        if (!metadata || !dirname || (fd < 0)) {
 
1022
        if (!metadata || !dirname) {
1061
1023
                return CL_ENULLARG;
1062
1024
        }
1063
1025
 
1064
1026
        if (metadata->encrypted) {
1065
1027
                cli_dbgmsg("PASSWORDed file (skipping)\n");
1066
 
                offset = lseek(fd, 0, SEEK_CUR) + metadata->comp_size;
1067
 
                cli_dbgmsg("Target offset: %lu\n", (unsigned long int) offset);
1068
 
                if (lseek(fd, offset, SEEK_SET) != offset) {
1069
 
                        return CL_ESEEK;
1070
 
                }
 
1028
                metadata->offset += metadata->comp_size;
 
1029
                cli_dbgmsg("Target offset: %lu\n", (unsigned long int) metadata->offset);
1071
1030
                return CL_SUCCESS;
1072
1031
        }
1073
 
        
 
1032
 
1074
1033
        snprintf(filename, 1024, "%s"PATHSEP"file.uar", dirname);
1075
1034
        cli_dbgmsg("Filename: %s\n", filename);
1076
1035
        metadata->ofd = open(filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
1079
1038
        }
1080
1039
        switch (metadata->method) {
1081
1040
                case 0:
1082
 
                        ret = arj_unstore(fd, metadata->ofd, metadata->comp_size);
1083
 
                        if (ret != metadata->comp_size) {
1084
 
                                ret = CL_EWRITE;
1085
 
                        } else {
1086
 
                                ret = CL_SUCCESS;
1087
 
                        }
 
1041
                        ret = arj_unstore(metadata, metadata->ofd, metadata->comp_size);
1088
1042
                        break;
1089
1043
                case 1:
1090
1044
                case 2:
1091
1045
                case 3:
1092
 
                        ret = decode(fd, metadata);
 
1046
                        ret = decode(metadata);
1093
1047
                        break;
1094
1048
                case 4:
1095
 
                        ret = decode_f(fd, metadata);
 
1049
                        ret = decode_f(metadata);
1096
1050
                        break;
1097
1051
                default:
1098
1052
                        ret = CL_EFORMAT;