From 984c1c6e4deb3b8113dee0220f6dcd1781824f28 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Wed, 4 Aug 2010 22:01:25 +0000 Subject: [PATCH] * Fixed an EOC marker sanity check in CSJ2K that was potentially reading past the end of the stream * If CSJ2K packet decoding tries to read past the end of the stream, just terminate the decoding and return what we have so far instead of throwing an exception. This experimental fix should improve the JPEG2000 decoding success rate git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3406 52acb1d6-8a22-11de-b505-999d5b087335 --- CSJ2K/j2k/codestream/reader/FileBitstreamReaderAgent.cs | 6 +++++- CSJ2K/j2k/codestream/reader/PktDecoder.cs | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CSJ2K/j2k/codestream/reader/FileBitstreamReaderAgent.cs b/CSJ2K/j2k/codestream/reader/FileBitstreamReaderAgent.cs index 4dfaecf7..8eb1e54c 100644 --- a/CSJ2K/j2k/codestream/reader/FileBitstreamReaderAgent.cs +++ b/CSJ2K/j2k/codestream/reader/FileBitstreamReaderAgent.cs @@ -598,7 +598,11 @@ namespace CSJ2K.j2k.codestream.reader { try { - if (!rateReached && !isPsotEqualsZero && in_Renamed.readShort() != CSJ2K.j2k.codestream.Markers.EOC) + short eocCheck = 0; + if (in_Renamed.Pos + 2 < in_Renamed.length()) + eocCheck = in_Renamed.readShort(); + + if (!rateReached && !isPsotEqualsZero && eocCheck != CSJ2K.j2k.codestream.Markers.EOC) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "EOC marker not found. " + "Codestream is corrupted."); } diff --git a/CSJ2K/j2k/codestream/reader/PktDecoder.cs b/CSJ2K/j2k/codestream/reader/PktDecoder.cs index 27a4ec59..ac4390d5 100644 --- a/CSJ2K/j2k/codestream/reader/PktDecoder.cs +++ b/CSJ2K/j2k/codestream/reader/PktDecoder.cs @@ -1433,7 +1433,13 @@ namespace CSJ2K.j2k.codestream.reader ccb.ntp[l] = 0; ccb.pktIdx[l] = - 1; } - throw new System.IO.EndOfStreamException(); + + // JH: If we try and seek past the end of the stream just stop the decoding + curOff = ehs.length() - 1; + ehs.seek(curOff); + stopRead = true; + return true; + //throw new System.IO.EndOfStreamException(); } // If truncation mode