Skip to content

Fix for crash when using old AVI File Writer calls #7

Description

@TroikaTronix

Hello,

So in preparing for the release of Isadora 3, I discovered a bug that's easily fixed. The crash happens when calling AVIStreamWrite which is part of the old VfW output system.

The bug and the fist are shown in this snippet from compression.cpp / CodecInst::Compress(ICCOMPRESS* icinfo, DWORD dwSize)

unsigned int compressorOptions = HapCompressorNone;
if (_useSnappy) {
	compressorOptions |= HapCompressorSnappy;
}

unsigned long maxOutputSize = icinfo->dwFrameSize;

// BEGIN CHANGES

// from: Mark Coniglio / TroikaTronix
//
// the original code below seems to be wrong.
// it compared biSizeImage to maxOutputSize 
// (dwFrameSize) and, if it was greater, used that
// for the max output size. but the Microsoft docs on 
// dwFrameSize say the following:
//
// Desired maximum size, in bytes, for compressing
// this frame. The size value is used for compression
// methods that can make tradeoffs between compressed
// image size and image quality. Specify zero for this
// member to use the default setting.
//
// so, if dwFrameSize is zero (indicating that the
// default size should be used), then biSizeImage is
// used as the max instead. but, biSizeImage was set
// as the size of the previous frame... it may not
// be the actual size.
//
// i am inferring that the initial request for the 
// maximum buffer size determines the size of the
// buffer. so, if dwFrameSize is zero, we use that
// as the maximum.

/*

>>> deleted / erroneous code was as follows <<<

if (icinfo->lpbiOutput->biSizeImage > maxOutputSize) {
	maxOutputSize = icinfo->lpbiOutput->biSizeImage;
}

*/

// this is the fixed code
if (maxOutputSize == 0) {
	maxOutputSize = CompressGetSize(icinfo->lpbiInput, icinfo->lpbiOutput);
}

// END OF CHANGES

unsigned long outputBufferBytesUsed = 0;
switch (_codecType)
{
case Hap:
	outputBufferBytesUsed = CompressHap(input, icinfo->lpOutput, maxOutputSize, compressorOptions);
	break;
case HapAlpha:
	outputBufferBytesUsed = CompressHapAlpha(input, icinfo->lpOutput, maxOutputSize, compressorOptions);
	break;
case HapQ:
	outputBufferBytesUsed = CompressHapQ(input, icinfo->lpOutput, maxOutputSize, compressorOptions);
	break;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions