BViewState* BViewState::InstantiateFromStream(BMallocIO* stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE); int32 version = kViewStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (!ValidateStream(stream, key, version)) return NULL; return _Sanitize(new (std::nothrow) BViewState(stream, endianSwap)); }
BColumn * BColumn::InstantiateFromStream(BMallocIO *stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BColumn", B_OBJECT_TYPE); int32 version = kColumnStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } // PRINT(("validating key %x, version %d\n", key, version)); if (!ValidateStream(stream, key, version)) return 0; // PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : "")); BColumn *result = new BColumn(stream, endianSwap); // sanity-check the resulting column if (result->fTitle.Length() > 500 || result->fOffset < 0 || result->fOffset > 10000 || result->fWidth < 0 || result->fWidth > 10000 || (int32)result->fAlignment < B_ALIGN_LEFT || (int32)result->fAlignment > B_ALIGN_CENTER || result->fAttrName.Length() > 500) { PRINT(("column data not valid\n")); delete result; return 0; } #if DEBUG else if (endianSwap) PRINT(("Instantiated foreign column ok\n")); #endif return result; }
BViewState * BViewState::InstantiateFromStream(BMallocIO *stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE); int32 version = kViewStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (!ValidateStream(stream, key, version)) return NULL; BViewState *result = new BViewState(stream, endianSwap); // do a sanity check here if ((result->fViewMode != kListMode && result->fViewMode != kIconMode && result->fViewMode != kMiniIconMode && result->fViewMode != 0) || (result->fLastIconMode != kListMode && result->fLastIconMode != kIconMode && result->fLastIconMode != kMiniIconMode && result->fLastIconMode != 0)) { PRINT(("Bad data instantiating ViewState, view mode %x, lastIconMode %x\n", result->fViewMode, result->fLastIconMode)); delete result; return NULL; } #if DEBUG else if (endianSwap) PRINT(("Instantiated foreign view state ok\n")); #endif return result; }
BColumn* BColumn::InstantiateFromStream(BMallocIO* stream, bool endianSwap) { // compare stream header in canonical form // we can't use ValidateStream(), as we preserve backwards compatibility int32 version; uint32 key; if (stream->Read(&key, sizeof(uint32)) <= 0 || stream->Read(&version, sizeof(int32)) <=0) return 0; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (key != AttrHashString("BColumn", B_OBJECT_TYPE) || version < kColumnStateMinArchiveVersion) return 0; // PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : "")); return _Sanitize(new (std::nothrow) BColumn(stream, version, endianSwap)); }