Skip to content

Commit 2ee9afa

Browse files
MXF parsing: terminate strings on the first null character (#373)
Per SMPTE ST 377-1:2019, a "zero value" can be used to terminate a string. So, discard any data after the first null character found (if any). This has the same effect as the implementation for strings in regxmllib at: https://github.com/sandflow/regxmllib/blob/b47b0cdbd6dbf51cae4fb14c3a6a827eb3e0e2cc/src/main/java/com/sandflow/smpte/regxml/FragmentBuilder.java#L902 Note that regxmllib also uses the same `readCharacters` method for MXF properties with a Type of Type Kind "Character", and allows values of this Type to contain the null character. Photon does not support such "Character" Types (and indeed none have ever been used in MXF according to the SMPTE Metadata Registers). So, no consideration is given to these Types in this patch.
1 parent 096bff9 commit 2ee9afa

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/main/java/com/netflix/imflibrary/MXFPropertyPopulator.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,20 @@ else if ((field.getType() == Boolean.class) && (byteArraySize == 1))
253253
}
254254

255255
/**
256-
* Getter for a string representing the byte[]
256+
* Getter for a string representing the byte[], terminating on the first null character
257257
*
258258
* @param byteArray the byte array
259259
* @param charset the charset
260260
* @return the string
261261
*/
262262
public static String getString(byte[] byteArray, Charset charset)
263263
{
264-
return new String(byteArray, charset);
264+
String s = new String(byteArray, charset);
265+
int i = s.indexOf('\u0000');
266+
if (i == -1) {
267+
return s;
268+
}
269+
return s.substring(0, i);
265270
}
266271

267272
/**

src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,13 @@ public void IMPAnalyzerAnalyzeUnknownFileError() throws IOException
214214

215215
}
216216

217+
@Test
218+
public void IMPAnalyzerAnalyzeTrackFileNullTerminatedStrings() throws IOException
219+
{
220+
File inputFile = TestHelper.findResourceByPath("IMFTrackFiles/AUDIO.null_terminated_strings.mxf");
221+
List<ErrorLogger.ErrorObject> errorList = analyzeFile(inputFile);
222+
Assert.assertEquals(errorList.size(), 0);
223+
224+
}
225+
217226
}
Binary file not shown.

0 commit comments

Comments
 (0)