Skip to content

Commit 4e4c6cc

Browse files
FFV1: if slice CRC error, try to decode anyway
1 parent 5047e91 commit 4e4c6cc

File tree

13 files changed

+60
-28
lines changed

13 files changed

+60
-28
lines changed

Source/Lib/CoDec/FFV1/FFV1_Frame.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ bool ffv1_frame::Process(const uint8_t* Buffer, size_t Buffer_Size)
224224

225225
RawFrame->Finalize(P.num_h_slices, P.num_v_slices);
226226

227-
return false;
227+
return P.Error() ? true : false;
228228
}
229229

230230
//***************************************************************************
231231
// Errors
232232
//***************************************************************************
233233

234234
//---------------------------------------------------------------------------
235-
const char* ffv1_frame::ErrorMessage()
235+
const char* ffv1_frame::ErrorMessage() const
236236
{
237-
return P.error_message;
237+
return P.Error();
238238
}
239239

240240
//***************************************************************************

Source/Lib/CoDec/FFV1/FFV1_Frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ffv1_frame
3939
raw_frame* RawFrame;
4040

4141
// Error message
42-
const char* ErrorMessage();
42+
const char* ErrorMessage() const;
4343

4444
private:
4545
// Parameters

Source/Lib/CoDec/FFV1/FFV1_Parameters.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,26 @@ bool parameters::Parse(rangecoder& E, bool ConfigurationRecord_IsPresent)
182182
return false;
183183
}
184184

185+
//---------------------------------------------------------------------------
186+
bool parameters::Error(const char* Error)
187+
{
188+
const char* expected = nullptr;
189+
error_message.compare_exchange_strong(
190+
expected,
191+
Error,
192+
std::memory_order_release,
193+
std::memory_order_relaxed
194+
);
195+
196+
return true;
197+
}
198+
199+
//---------------------------------------------------------------------------
200+
const char* parameters::Error() const
201+
{
202+
return error_message.load(std::memory_order_acquire);
203+
}
204+
185205
//---------------------------------------------------------------------------
186206
bool parameters::QuantizationTableSet(rangecoder& E, size_t i)
187207
{

Source/Lib/CoDec/FFV1/FFV1_Parameters.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Lib/CoDec/FFV1/FFV1_RangeCoder.h"
1414
#include "Lib/CoDec/FFV1/Coder/FFV1_Coder_RangeCoder.h"
1515
#include "Lib/CoDec/FFV1/Coder/FFV1_Coder.h"
16+
#include <atomic>
1617
#include <cstring>
1718
using namespace std;
1819
//---------------------------------------------------------------------------
@@ -32,7 +33,8 @@ struct parameters
3233

3334
// Run
3435
bool Parse(rangecoder& E, bool ConfigurationRecord_IsPresent);
35-
bool Error(const char* Error) { error_message = Error; return true; }
36+
bool Error(const char* Error);
37+
const char* Error() const;
3638

3739
// Common content
3840
uint32_t version;
@@ -67,7 +69,7 @@ struct parameters
6769
bool IsOverflow16bit;
6870

6971
// Error message
70-
const char* error_message = nullptr;
72+
std::atomic<const char*> error_message = { nullptr };
7173

7274
private:
7375
bool QuantizationTableSet(rangecoder& E, size_t i);

Source/Lib/CoDec/FFV1/FFV1_Slice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ bool slice::Parse()
246246

247247
// CRC check
248248
if (P->ec == 1 && ZenCRC32(Buffer, Buffer_Size))
249-
return P->Error("FFV1-SLICE-slice_crc_parity:1");
249+
P->Error("FFV1-SLICE-slice_crc_parity:1"); // We do not stop here, to try to decode the slice anyway
250250

251251
// RangeCoder reset
252252
Buffer_Size -= P->TailSize;

Source/Lib/CoDec/Wrapper.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class ffv1_wrapper : public video_wrapper
8080
void SetHeight(uint32_t Height);
8181

8282
// Actions
83-
void Process(const uint8_t* Data, size_t Size);
84-
void OutOfBand(const uint8_t* Data, size_t Size);
83+
bool Process(const uint8_t* Data, size_t Size);
84+
bool OutOfBand(const uint8_t* Data, size_t Size);
8585

8686
private:
8787
ffv1_frame* Ffv1Frame;
@@ -112,18 +112,19 @@ void ffv1_wrapper::SetHeight(uint32_t Height)
112112
}
113113

114114
//---------------------------------------------------------------------------
115-
void ffv1_wrapper::Process(const uint8_t* Data, size_t Size)
115+
bool ffv1_wrapper::Process(const uint8_t* Data, size_t Size)
116116
{
117117
Ffv1Frame->RawFrame = RawFrame;
118-
Ffv1Frame->Process(Data, Size);
118+
auto Value = Ffv1Frame->Process(Data, Size);
119119
RawFrame->Process();
120+
return Value;
120121
}
121122

122123
//---------------------------------------------------------------------------
123-
void ffv1_wrapper::OutOfBand(const uint8_t* Data, size_t Size)
124+
bool ffv1_wrapper::OutOfBand(const uint8_t* Data, size_t Size)
124125
{
125126
Ffv1Frame->RawFrame = RawFrame;
126-
Ffv1Frame->OutOfBand(Data, Size);
127+
return Ffv1Frame->OutOfBand(Data, Size);
127128
}
128129

129130
//---------------------------------------------------------------------------
@@ -134,8 +135,8 @@ class flac_wrapper : public audio_wrapper
134135
~flac_wrapper();
135136

136137
// Actions
137-
void OutOfBand(const uint8_t* Data, size_t Size) { return Process(Data, Size); }
138-
void Process(const uint8_t* Data, size_t Size);
138+
bool OutOfBand(const uint8_t* Data, size_t Size) { return Process(Data, Size); }
139+
bool Process(const uint8_t* Data, size_t Size);
139140

140141
// libFLAC related helping functions
141142
void FLAC_Read(uint8_t buffer[], size_t* bytes);
@@ -200,20 +201,20 @@ flac_wrapper::~flac_wrapper()
200201
FLAC__stream_decoder_delete(Decoder_);
201202
}
202203

203-
void flac_wrapper::Process(const uint8_t* Data, size_t Size)
204+
bool flac_wrapper::Process(const uint8_t* Data, size_t Size)
204205
{
205206
Data_ = Data;
206207
Size_ = Size;
207208

208209
for (;;)
209210
{
210211
if (!FLAC__stream_decoder_process_single(Decoder_))
211-
break;
212+
return true;
212213
FLAC__uint64 Pos;
213214
if (!FLAC__stream_decoder_get_decode_position(Decoder_, &Pos))
214-
break;
215+
return true;
215216
if (Pos == absolute_byte_offset_)
216-
break;
217+
return false;
217218
}
218219
}
219220

@@ -376,14 +377,14 @@ class pcm_wrapper : public audio_wrapper
376377
{
377378
public:
378379
// Actions
379-
void Process(const uint8_t* Data, size_t Size);
380+
bool Process(const uint8_t* Data, size_t Size);
380381
};
381382

382383
//---------------------------------------------------------------------------
383-
void pcm_wrapper::Process(const uint8_t* Data, size_t Size)
384+
bool pcm_wrapper::Process(const uint8_t* Data, size_t Size)
384385
{
385386
RawFrame->AssignBufferView(Data, Size);
386-
RawFrame->Process();
387+
return RawFrame->Process();
387388
}
388389

389390
//---------------------------------------------------------------------------

Source/Lib/CoDec/Wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class base_wrapper
3333
virtual ~base_wrapper() {}
3434

3535
// Actions
36-
virtual void Process(const uint8_t* Data, size_t Size) = 0;
37-
inline virtual void OutOfBand(const uint8_t* /*Data*/, size_t /*Size*/) {};
36+
virtual bool Process(const uint8_t* Data, size_t Size) = 0;
37+
inline virtual bool OutOfBand(const uint8_t* /*Data*/, size_t /*Size*/) { return true; };
3838

3939
public:
4040
raw_frame* RawFrame = nullptr;

Source/Lib/Compressed/RAWcooked/Track.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ bool track_info::Process(const uint8_t* Data, size_t Size)
9999
Errors->Error(IO_FileChecker, error::type::Undecodable, (error::generic::code)filechecker_issue::undecodable::Format_Undetected, string());
100100
return true;
101101
}
102-
Wrapper->Process(Data, Size);
102+
if (Wrapper->Process(Data, Size))
103+
{
104+
string OutputFileName = ReversibilityData->Data(reversibility::element::FileName);
105+
FormatPath(OutputFileName);
106+
Errors->Error(IO_FileChecker, error::type::Undecodable, (error::generic::code)filechecker_issue::undecodable::Frame_Compressed_Issue, OutputFileName);
107+
}
103108
if (ReversibilityData && !ReversibilityData->Unique())
104109
{
105110
if (Actions[Action_Conch] || Actions[Action_Coherency])

Source/Lib/Uncompressed/HashSum/HashSum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const char** ErrorTexts[] =
6666

6767
static_assert(error::type_Max == sizeof(ErrorTexts) / sizeof(const char**), IncoherencyMessage);
6868

69-
} // filechecker_issue
69+
} // hashes_issue
7070

7171
//***************************************************************************
7272
// Hashes

Source/Lib/Utils/FileIO/FileChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace filechecker_issue {
2424
"extra attachments in source (missing attachments in compressed file)",
2525
"missing frame in compressed file",
2626
"extra frame in compressed file",
27+
"frame (encoder can not decode it)",
2728
"missing frame in source (extra frames in compressed file)",
2829
"extra frame in source (missing frames in compressed file)",
2930
"track format (unsupported)",

0 commit comments

Comments
 (0)