diff --git a/.github/workflows/build_and_test_macos.yml b/.github/workflows/build_and_test_macos.yml new file mode 100644 index 000000000..eecaf0f05 --- /dev/null +++ b/.github/workflows/build_and_test_macos.yml @@ -0,0 +1,28 @@ +name: Build and test [MacOS] + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@master + + - name: Set up dotnet core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 2.1.x + 6.0.x + 8.0.x + + # Build the release build + - name: Build the solution + run: dotnet build -c Release src/UglyToad.PdfPig.sln + + - name: Run the tests + run: dotnet test -c Release src/UglyToad.PdfPig.sln diff --git a/src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs b/src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs index b9089ebf4..0e716b957 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs @@ -1,14 +1,22 @@ namespace UglyToad.PdfPig.Tests.Integration { + using PdfPig.Fonts.SystemFonts; using System.Linq; public class LetterFilterTests { - [Fact] + [SkippableFact] public void CanFilterClippedLetters() { var one = IntegrationHelpers.GetDocumentPath("ClipPathLetterFilter-Test1.pdf"); + // The 'TimesNewRomanPSMT' font is used by this particular document. Thus, results cannot be trusted on + // platforms where this font isn't generally available (e.g. OSX, Linux, etc.), so we skip it! + var font = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPSMT"); + var font1 = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPS-BoldMT"); + var font2 = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPS-ItalicMT"); + Skip.If(font is null || font1 is null || font2 is null, "Skipped because the font TimesNewRomanPSMT or a font from TimesNewRoman family could not be found in the execution environment."); + using (var doc1 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = true })) using (var doc2 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = false })) { diff --git a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs index 286c6040c..bfa12ea44 100644 --- a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs +++ b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs @@ -1252,18 +1252,18 @@ public void CanCreateDocumentWithOutline() bookmarks.GetNodes().OfType().Select(node => node.Uri)); Assert.Equal( - new[] + new byte[] { - ExplicitDestinationType.XyzCoordinates, - ExplicitDestinationType.FitPage, - ExplicitDestinationType.FitRectangle, - ExplicitDestinationType.FitBoundingBox, - ExplicitDestinationType.FitBoundingBoxHorizontally, - ExplicitDestinationType.FitBoundingBoxVertically, - ExplicitDestinationType.FitHorizontally, - ExplicitDestinationType.FitVertically, + (byte)ExplicitDestinationType.XyzCoordinates, + (byte)ExplicitDestinationType.FitPage, + (byte)ExplicitDestinationType.FitRectangle, + (byte)ExplicitDestinationType.FitBoundingBox, + (byte)ExplicitDestinationType.FitBoundingBoxHorizontally, + (byte)ExplicitDestinationType.FitBoundingBoxVertically, + (byte)ExplicitDestinationType.FitHorizontally, + (byte)ExplicitDestinationType.FitVertically, }, - bookmarks.GetNodes().OfType().Select(node => node.Destination.Type)); + bookmarks.GetNodes().OfType().Select(node => (byte)node.Destination.Type)); } } diff --git a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs index b9b400232..ba1e32ccd 100644 --- a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs +++ b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs @@ -1,13 +1,13 @@ namespace UglyToad.PdfPig.Encryption { using System; - using System.IO; using System.Security.Cryptography; internal static class AesEncryptionHelper { public static byte[] Encrypt256() { + // See https://stackoverflow.com/questions/73779169/cryptographicexception-bad-pkcs7-padding-invalid-length-0-cannot-decrypt-sa throw new NotImplementedException(); } @@ -27,35 +27,28 @@ public static byte[] Decrypt(byte[] data, byte[] finalKey) aes.IV = iv; #if NET8_0_OR_GREATER - var encryptedData = data.AsSpan(iv.Length); - if (encryptedData.IsEmpty) + if (data.Length <= iv.Length) { + aes.Clear(); return []; } - return aes.DecryptCbc(encryptedData, iv, PaddingMode.PKCS7); + + var encryptedData = data.AsSpan(iv.Length); + var output = aes.DecryptCbc(encryptedData, iv, PaddingMode.PKCS7); + aes.Clear(); + return output; #else - var buffer = new byte[256]; + if (data.Length <= iv.Length) + { + aes.Clear(); + return []; + } using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV)) - using (var input = new MemoryStream(data)) - using (var output = new MemoryStream()) { - input.Seek(iv.Length, SeekOrigin.Begin); - using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read)) - { - int read; - do - { - read = cryptoStream.Read(buffer, 0, buffer.Length); - - if (read > 0) - { - output.Write(buffer, 0, read); - } - } while (read > 0); - - return output.ToArray(); - } + var output = decryptor.TransformFinalBlock(data, iv.Length, data.Length - iv.Length); + aes.Clear(); + return output; } #endif } diff --git a/src/UglyToad.PdfPig/Outline/Destinations/ExplicitDestinationType.cs b/src/UglyToad.PdfPig/Outline/Destinations/ExplicitDestinationType.cs index 03800dd2e..132354273 100644 --- a/src/UglyToad.PdfPig/Outline/Destinations/ExplicitDestinationType.cs +++ b/src/UglyToad.PdfPig/Outline/Destinations/ExplicitDestinationType.cs @@ -3,7 +3,7 @@ /// /// The display type for opening an . /// - public enum ExplicitDestinationType + public enum ExplicitDestinationType : byte { /// /// Display the page with the given top left coordinates and