Do not throw if the Mask dictionary contains a ColorSpace key

This commit is contained in:
BobLd
2025-05-30 07:40:32 +01:00
parent 4bdb85d1ff
commit d9b3891eb3
3 changed files with 28 additions and 4 deletions

View File

@@ -7,6 +7,24 @@
public class GithubIssuesTests
{
[Fact]
public void Issue1054()
{
var path = IntegrationHelpers.GetSpecificTestDocumentPath("MOZILLA-11518-0.pdf");
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
{
for (int p = 1; p <= document.NumberOfPages; p++)
{
var page = document.GetPage(p);
foreach (var image in page.GetImages())
{
Assert.NotNull(image);
}
}
}
}
[Fact]
public void Issue1050()
{

View File

@@ -73,10 +73,16 @@
}
else if (dictionary.TryGet(NameToken.Mask, out StreamToken maskStream))
{
if (maskStream.StreamDictionary.ContainsKey(NameToken.ColorSpace))
{
throw new Exception("The SMask dictionary contains a 'ColorSpace'.");
}
/* As per Pdf Specifications:
* "The image dictionary shall not contain a ColorSpace entry because sample values represent masking properties (1 bit per sample) rather than colours."
*
* TODO - We assume here lenient parsing, but we should actually get the value from parsing options. See Issue #1054
*
* if (maskStream.StreamDictionary.ContainsKey(NameToken.ColorSpace))
* {
* throw new Exception("The SMask dictionary contains a 'ColorSpace'.");
* }
*/
// Stencil masking
XObjectContentRecord maskImageRecord = new XObjectContentRecord(XObjectType.Image,