Public cFileName As String = "" Public nCRC32 As Integer = 0 Private nBufferSize As Integer = 1024 Private nCRC32Table() As Integer ' This is the official polynomial used by CRC32 in PKZip. ' Often the polynomial is shown reversed (04C11DB7). Private Sub Init() Dim lnDWPolynomial As Integer = &HEDB88320 Dim lnCounter As Integer = 0 Dim lnCounter2 As Integer = 0 ReDim nCRC32Table(256) Dim lnDWCRC As Integer For lnCounter = 0 To 255 lnDWCRC = lnCounter For lnCounter2 = 8 To 1 Step -1 If (lnDWCRC And 1) Then lnDWCRC = ((lnDWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF lnDWCRC = lnDWCRC Xor lnDWPolynomial Else lnDWCRC = ((lnDWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF End If Next nCRC32Table(lnCounter) = lnDWCRC Next End Sub ' This is the main method to call Public Function GetCRC() As Boolean Dim loStream As Stream loStream = New FileStream(cFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) nCRC32 = GetCrc32(loStream) loStream.Close() Return True End Function Private Function GetCrc32(ByRef toStream As System.IO.Stream) As Integer Dim lnCRC32Result As Integer = &HFFFFFFFF Dim loBuffer(nBufferSize) As Byte Dim lnReadSize As Integer = nBufferSize Dim lnCount As Integer = 0 Dim lnCounter As Integer = 0 Dim lnLookup As Integer = 0 lnCount = toStream.Read(loBuffer, 0, lnReadSize) Do While lnCount > 0 For lnCounter = 0 To lnCount - 1 lnLookup = (lnCRC32Result And &HFF) Xor loBuffer(lnCounter) ' Nasty shr 8 with vb :/ lnCRC32Result = ((lnCRC32Result And &HFFFFFF00) \ &H100) And 16777215 lnCRC32Result = lnCRC32Result Xor nCRC32Table(lnLookup) Next lnCount = toStream.Read(loBuffer, 0, lnReadSize) Loop Return Not lnCRC32Result End FunctionThis method has always worked well. However, tonight, on a specific JPG, it returns:
lnCRC32Result = lnCRC32Result Xor nCRC32Table(lnLookup)I really don't understand how this line could return an object reference not set. Anyone would have any idea and also about what is causing this?