Fixed data corruption in InputStreams returned by FTLDat
This commit is contained in:
parent
97c54d26e3
commit
0bd9d9e9b9
2 changed files with 24 additions and 5 deletions
|
@ -8,6 +8,8 @@ Changelog
|
||||||
- The main window's geometry is saved on exit
|
- The main window's geometry is saved on exit
|
||||||
- Added urls in the statusbar when hovering over links
|
- Added urls in the statusbar when hovering over links
|
||||||
- Added periodic checking for SMM updates
|
- Added periodic checking for SMM updates
|
||||||
|
- Added FTL launching on Linux
|
||||||
|
- Fixed critical bugs in InputStreams returned by FTLDat
|
||||||
|
|
||||||
1.1:
|
1.1:
|
||||||
- Added a button to open the mods/ folder
|
- Added a button to open the mods/ folder
|
||||||
|
|
|
@ -62,8 +62,9 @@ public class FileChannelRegionInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do an absolute get() from the buffer.
|
// Do an absolute get() from the buffer,
|
||||||
int result = buf.get( (int)(intraPos - bufOffset) );
|
// and interpret the byte as if it were unsigned.
|
||||||
|
int result = (int)(buf.get( (int)(intraPos - bufOffset) ) & 0xff);
|
||||||
intraPos++;
|
intraPos++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -78,14 +79,16 @@ public class FileChannelRegionInputStream extends InputStream {
|
||||||
|
|
||||||
int bytesTotal = Math.min( bLen, (int)(regionLength - intraPos) );
|
int bytesTotal = Math.min( bLen, (int)(regionLength - intraPos) );
|
||||||
int bytesRemaining = bytesTotal;
|
int bytesRemaining = bytesTotal;
|
||||||
|
int bytesRead = 0;
|
||||||
|
|
||||||
if ( intraPos >= bufOffset || intraPos < bufOffset+bufLength ) {
|
if ( intraPos >= bufOffset && intraPos < bufOffset+bufLength ) {
|
||||||
// Read part of the current buffer, possibly until the end.
|
// Read part of the current buffer, possibly until the end.
|
||||||
|
|
||||||
buf.position( (int)(intraPos - bufOffset) );
|
buf.position( (int)(intraPos - bufOffset) );
|
||||||
int bufTodo = Math.min( bytesRemaining, bufLength - (int)(intraPos - bufOffset) );
|
int bufTodo = Math.min( bytesRemaining, bufLength - (int)(intraPos - bufOffset) );
|
||||||
buf.get( b, bOff, bufTodo );
|
buf.get( b, bOff, bufTodo );
|
||||||
bytesRemaining -= bufTodo;
|
bytesRemaining -= bufTodo;
|
||||||
|
bytesRead += bufTodo;
|
||||||
intraPos += bufTodo;
|
intraPos += bufTodo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +108,25 @@ public class FileChannelRegionInputStream extends InputStream {
|
||||||
|
|
||||||
buf.position( 0 );
|
buf.position( 0 );
|
||||||
int bufTodo = Math.min( bytesRemaining, bufLength );
|
int bufTodo = Math.min( bytesRemaining, bufLength );
|
||||||
buf.get( b, bOff, bufTodo );
|
buf.get( b, bOff + bytesRead, bufTodo );
|
||||||
bytesRemaining -= bufTodo;
|
bytesRemaining -= bufTodo;
|
||||||
|
bytesRead += bufTodo;
|
||||||
intraPos += bufTodo;
|
intraPos += bufTodo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( bytesTotal - bytesRemaining ); // Return number of bytes read.
|
return bytesRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long skip( long n ) throws IOException {
|
||||||
|
if ( !channel.isOpen() ) throw new ClosedChannelException();
|
||||||
|
if ( intraPos >= regionLength ) return -1;
|
||||||
|
|
||||||
|
if ( intraPos + n <= regionLength ) {
|
||||||
|
n = regionLength - intraPos;
|
||||||
|
}
|
||||||
|
intraPos += n;
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue