Skip to content

Commit

Permalink
MXF parsing: terminate strings on the first null character (#373)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheritage authored Nov 20, 2024
1 parent 096bff9 commit 2ee9afa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,20 @@ else if ((field.getType() == Boolean.class) && (byteArraySize == 1))
}

/**
* Getter for a string representing the byte[]
* Getter for a string representing the byte[], terminating on the first null character
*
* @param byteArray the byte array
* @param charset the charset
* @return the string
*/
public static String getString(byte[] byteArray, Charset charset)
{
return new String(byteArray, charset);
String s = new String(byteArray, charset);
int i = s.indexOf('\u0000');
if (i == -1) {
return s;
}
return s.substring(0, i);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,13 @@ public void IMPAnalyzerAnalyzeUnknownFileError() throws IOException

}

@Test
public void IMPAnalyzerAnalyzeTrackFileNullTerminatedStrings() throws IOException
{
File inputFile = TestHelper.findResourceByPath("IMFTrackFiles/AUDIO.null_terminated_strings.mxf");
List<ErrorLogger.ErrorObject> errorList = analyzeFile(inputFile);
Assert.assertEquals(errorList.size(), 0);

}

}
Binary file not shown.

0 comments on commit 2ee9afa

Please sign in to comment.