Q:

c# RijndaelManaged encryption & decryption sometimes fails

Edit: solved - problem was the decryption function. Corrected decryption function can be found in the answer below.
I have spent the last day at work trying to figure out where I went wrong with this implementation of AES. We need to be able to encrypt/decrypt large files so I have used file streams and write to disk each chunk. AES is a requirement as this needs to work with an existing system written in java which uses AES/CBC/PKCS5Padding (which as far as I am aware is equivalent to PKCS7/CBC)
This implementation works for most files. However there are a few files where the last 5 bytes of raw data are missing. The file will decrypt without errors however the hash doesn't match and the missing bytes are a combination of real data and trailing zeros. 
It should be noted that these streams are gzipped before and after encryption (code at the bottom).
Encryption
    public static void AesEncrypt(byte[] keyBytes, byte[] ivBytes, Stream dataStream, FileStream outStream)
    {
        RijndaelManaged symmetricKey = new RijndaelManaged();
        symmetricKey.Mode = CipherMode.CBC;
        symmetricKey.Padding = PaddingMode.PKCS7;
        symmetricKey.BlockSize = 128;
        symmetricKey.KeySize = 256;

        const int chunkSize = 4096;//1024 * 1024 * 10;

        using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, ivBytes))
        {
            using (CryptoStream cryptoStream = new CryptoStream(outStream, encryptor, CryptoStreamMode.Write))
            {
                while (dataStream.Position != dataStream.Length)
                {
                    long remainingBytes = dataStream.Length - dataStream.Position;
                    var buffer = chunkSize > remainingBytes ? new byte[(int)remainingBytes] : new byte[chunkSize];

                    dataStream.Read(buffer, 0, buffer.Length);
                    cryptoStream.Write(buffer, 0, buffer.Length);
                    cryptoStream.Flush();
                }
                cryptoStream.FlushFinalBlock();
            }
        }
        symmetricKey.Clear();
    }

Decryption
    public static void AesDecrypt(byte[] keyBytes, byte[] ivBytes, Stream dataStream, FileStream outStream)
    {
        RijndaelManaged symmetricKey = new RijndaelManaged();
        symmetricKey.Mode = CipherMode.CBC;
        symmetricKey.Padding = PaddingMode.PKCS7;
        symmetricKey.BlockSize = 128;
        symmetricKey.KeySize = keyBytes.Length == 32 ? 256 : 128;

        const int chunkSize = 4096;

        using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, ivBytes))
        {
            using (CryptoStream cryptoStream = new CryptoStream(dataStream, decryptor, CryptoStreamMode.Read))
            {
                while (dataStream.Position != dataStream.Length)
                {
                    long remainingBytes = dataStream.Length - dataStream.Position;
                    var buffer = chunkSize > remainingBytes
                        ? new byte[(int) remainingBytes]
                        : new byte[chunkSize];

                    cryptoStream.Read(buffer, 0, buffer.Length);
                    outStream.Write(buffer, 0, buffer.Length);
                    outStream.Flush();
                }
                //cryptoStream.FlushFinalBlock(); // Was throwing an exception
            }
        }
        symmetricKey.Clear();
    }

Compression (Prior to encryption)
    public static void StreamCompress(Stream dataStream, FileStream outStream)
    {
        dataStream.Position = 0;
        outStream.Position = 0;

        const int chunkSize = 4096;
        using (GZipStream gzs = new GZipStream(outStream, CompressionMode.Compress))
        {
            while (dataStream.Position != dataStream.Length)
            {
                long remainingBytes = dataStream.Length - dataStream.Position;
                var buffer = chunkSize > remainingBytes ? new byte[(int)remainingBytes] : new byte[chunkSize];
                dataStream.Read(buffer, 0, buffer.Length);
                gzs.Write(buffer, 0, buffer.Length);
                gzs.Flush();
            }
        }
    }

Decompression (After decryption)
    public static void StreamDecompress(Stream dataStream, FileStream outStream)
    {
        byte[] buffer = new byte[4096];
        dataStream.Position = 0;
        using (GZipStream gzs = new GZipStream(dataStream, CompressionMode.Decompress))
        {
            for (int r = -1; r != 0; r = gzs.Read(buffer, 0, buffer.Length))
                if (r > 0) outStream.Write(buffer, 0, r);
        }
}

I have gone through some other questions but cannot figure out why this only occurs on some files. The file size which fails is 46,854,144 bytes. This seems to work fine with larger and smaller files though.
Any help would be greatly appreciated. 

A:

The issue was with the way I was decrypting the data. I was incorrectly using the CryptoStream. The updated Decrypt function is below if anyone was interested.
    public static void AesDecrypt(byte[] keyBytes, byte[] ivBytes, Stream dataStream, FileStream outStream)
    {
        dataStream.Position = 0;
        outStream.Position = 0;

        RijndaelManaged symmetricKey = new RijndaelManaged();
        symmetricKey.Mode = CipherMode.CBC;
        symmetricKey.Padding = PaddingMode.PKCS7;
        symmetricKey.BlockSize = 128;
        symmetricKey.KeySize = keyBytes.Length == 32 ? 256 : 128;

        const int chunkSize = 4096;

        using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, ivBytes))
        {
            using (CryptoStream cryptoStream = new CryptoStream(outStream, decryptor, CryptoStreamMode.Write))
            {

                while (dataStream.Position != dataStream.Length)
                {
                    long remainingBytes = dataStream.Length - dataStream.Position;
                    var buffer = chunkSize > remainingBytes
                        ? new byte[(int) remainingBytes]
                        : new byte[chunkSize];

                    var bytesRead = dataStream.Read(buffer, 0, buffer.Length);
                    cryptoStream.Write(buffer, 0, bytesRead);   
                }
                cryptoStream.FlushFinalBlock();
            }
        }
        symmetricKey.Clear();
    }

