Merge pull request #3325 from kapodamy/int-overflow-2-fixes
Integer overflow fixes in downloader
This commit is contained in:
commit
da2b059802
5 changed files with 13 additions and 12 deletions
|
@ -69,6 +69,11 @@ public class DataReader {
|
||||||
return primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3];
|
return primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long readUnsignedInt() throws IOException {
|
||||||
|
long value = readInt();
|
||||||
|
return value & 0xffffffffL;
|
||||||
|
}
|
||||||
|
|
||||||
public short readShort() throws IOException {
|
public short readShort() throws IOException {
|
||||||
primitiveRead(SHORT_SIZE);
|
primitiveRead(SHORT_SIZE);
|
||||||
return (short) (primitive[0] << 8 | primitive[1]);
|
return (short) (primitive[0] << 8 | primitive[1]);
|
||||||
|
|
|
@ -294,10 +294,6 @@ public class Mp4DashReader {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private long readUint() throws IOException {
|
|
||||||
return stream.readInt() & 0xffffffffL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasFlag(int flags, int mask) {
|
public static boolean hasFlag(int flags, int mask) {
|
||||||
return (flags & mask) == mask;
|
return (flags & mask) == mask;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +313,7 @@ public class Mp4DashReader {
|
||||||
private Box readBox() throws IOException {
|
private Box readBox() throws IOException {
|
||||||
Box b = new Box();
|
Box b = new Box();
|
||||||
b.offset = stream.position();
|
b.offset = stream.position();
|
||||||
b.size = stream.readInt();
|
b.size = stream.readUnsignedInt();
|
||||||
b.type = stream.readInt();
|
b.type = stream.readInt();
|
||||||
|
|
||||||
if (b.size == 1) {
|
if (b.size == 1) {
|
||||||
|
@ -478,7 +474,7 @@ public class Mp4DashReader {
|
||||||
private long parse_tfdt() throws IOException {
|
private long parse_tfdt() throws IOException {
|
||||||
int version = stream.read();
|
int version = stream.read();
|
||||||
stream.skipBytes(3);// flags
|
stream.skipBytes(3);// flags
|
||||||
return version == 0 ? readUint() : stream.readLong();
|
return version == 0 ? stream.readUnsignedInt() : stream.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Trun parse_trun() throws IOException {
|
private Trun parse_trun() throws IOException {
|
||||||
|
@ -551,7 +547,7 @@ public class Mp4DashReader {
|
||||||
stream.skipBytes(2 * (version == 0 ? 4 : 8));
|
stream.skipBytes(2 * (version == 0 ? 4 : 8));
|
||||||
|
|
||||||
Mvhd obj = new Mvhd();
|
Mvhd obj = new Mvhd();
|
||||||
obj.timeScale = readUint();
|
obj.timeScale = stream.readUnsignedInt();
|
||||||
|
|
||||||
// chunkDuration
|
// chunkDuration
|
||||||
stream.skipBytes(version == 0 ? 4 : 8);
|
stream.skipBytes(version == 0 ? 4 : 8);
|
||||||
|
@ -563,7 +559,7 @@ public class Mp4DashReader {
|
||||||
// predefined
|
// predefined
|
||||||
stream.skipBytes(76);
|
stream.skipBytes(76);
|
||||||
|
|
||||||
obj.nextTrackId = readUint();
|
obj.nextTrackId = stream.readUnsignedInt();
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -582,7 +578,7 @@ public class Mp4DashReader {
|
||||||
|
|
||||||
stream.skipBytes(4);// reserved
|
stream.skipBytes(4);// reserved
|
||||||
|
|
||||||
obj.duration = version == 0 ? readUint() : stream.readLong();
|
obj.duration = version == 0 ? stream.readUnsignedInt() : stream.readLong();
|
||||||
|
|
||||||
stream.skipBytes(2 * 4);// reserved
|
stream.skipBytes(2 * 4);// reserved
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Mp4FromDashWriter {
|
||||||
|
|
||||||
private int overrideMainBrand = 0x00;
|
private int overrideMainBrand = 0x00;
|
||||||
|
|
||||||
private ArrayList<Integer> compatibleBrands = new ArrayList<>(5);
|
private final ArrayList<Integer> compatibleBrands = new ArrayList<>(5);
|
||||||
|
|
||||||
public Mp4FromDashWriter(SharpStream... sources) throws IOException {
|
public Mp4FromDashWriter(SharpStream... sources) throws IOException {
|
||||||
for (SharpStream src : sources) {
|
for (SharpStream src : sources) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ChunkFileInputStream extends SharpStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long available() {
|
public long available() {
|
||||||
return (int) (length - position);
|
return length - position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("EmptyCatchBlock")
|
@SuppressWarnings("EmptyCatchBlock")
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class CircularFileWriter extends SharpStream {
|
||||||
available = out.length - offsetOut;
|
available = out.length - offsetOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = Math.min(len, (int) available);
|
int length = Math.min(len, (int) Math.min(Integer.MAX_VALUE, available));
|
||||||
out.write(b, off, length);
|
out.write(b, off, length);
|
||||||
|
|
||||||
len -= length;
|
len -= length;
|
||||||
|
|
Loading…
Reference in a new issue