sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 568 forks source link

Box.getBox is not thread safe #289

Open galbarm opened 6 years ago

galbarm commented 6 years ago

calling Box.getBox(WritableByteChannel writableByteChannel) from multiple threads has a race condition that sometimes ends with:

java.lang.IllegalArgumentException at java.nio.Buffer.position(Buffer.java:244) at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:209) at com.googlecode.mp4parser.util.ByteBufferByteChannel.write(ByteBufferByteChannel.java:52) at com.googlecode.mp4parser.AbstractBox.getBox(AbstractBox.java:136) at com.googlecode.mp4parser.BasicContainer.writeContainer(BasicContainer.java:216) at com.googlecode.mp4parser.AbstractContainerBox.getBox(AbstractContainerBox.java:88) at com.googlecode.mp4parser.BasicContainer.writeContainer(BasicContainer.java:216) at com.googlecode.mp4parser.AbstractContainerBox.getBox(AbstractContainerBox.java:88)

galbarm commented 6 years ago

Seems like it is caused due to modification of the position of private ByteBuffer content (in class AbstractBox)