ObjFW  Check-in [6b42e44f99]

Overview
Comment:OF{LHA,ZIP}Archive: Improve truncation detection
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6b42e44f99fd2b592aaf535bb8adce32fb70d2e7be2fd72f2378da9c884980fb
User & Date: js on 2018-06-10 20:29:27
Other Links: manifest | tags
Context
2018-06-12
21:33
Rename OFChecksum{Failed -> Mismatch}Exception check-in: 8f21e8acb5 user: js tags: trunk
2018-06-10
20:29
OF{LHA,ZIP}Archive: Improve truncation detection check-in: 6b42e44f99 user: js tags: trunk
15:33
Make GCC happy again check-in: 273171692b user: js tags: trunk
Changes

Modified src/OFInflateStream.m from [673c1237d7] to [929b5d3847].

669
670
671
672
673
674
675
676


677
678
679
680
681
682
683
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683
684







-
+
+







- (int)fileDescriptorForReading
{
	return [_stream fileDescriptorForReading];
}

- (bool)hasDataInReadBuffer
{
	return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]);
	return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer] ||
	    _bufferLength - _bufferIndex > 0);
}

- (void)close
{
	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];

Modified src/OFLHAArchive.m from [f7e8cf8472] to [4f0d23572a].

699
700
701
702
703
704
705
706


707
708
709
710
711
712
713
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713
714







-
+
+







- (int)fileDescriptorForReading
{
	return [_stream fileDescriptorForReading];
}

- (bool)hasDataInReadBuffer
{
	return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]);
	return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer] ||
	    _bufferLength - _bufferIndex > 0);
}

- (void)close
{
	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
789
790
791
792
793
794
795




796
797
798
799
800
801
802
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807







+
+
+
+








	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		return 0;

	if ([_stream isAtEndOfStream] &&
	    ![_decompressedStream hasDataInReadBuffer])
		@throw [OFTruncatedDataException exception];

	if (length > _toRead)
		length = _toRead;

	ret = [_decompressedStream readIntoBuffer: buffer
					   length: length];

	_toRead -= ret;

Modified src/OFZIPArchive.m from [f05c35edb7] to [0463ac5206].

793
794
795
796
797
798
799




800
801
802
803
804
805
806
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810







+
+
+
+








	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		return 0;

	if ([_stream isAtEndOfStream] &&
	    ![_decompressedStream hasDataInReadBuffer])
		@throw [OFTruncatedDataException exception];

#if SIZE_MAX >= UINT64_MAX
	if (length > UINT64_MAX)
		@throw [OFOutOfRangeException exception];
#endif

	if ((uint64_t)length > _toRead)
		length = (size_t)_toRead;