Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mocchira committed Nov 24, 2016
1 parent 9638dda commit 0607c70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions include/leo_object_storage.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@
%% Max Data Block Size to be larger than leo_gateway's large object settings
-define(MAX_DATABLOCK_SIZE, 1024 * 1024 * 10).

%% Constants to validate a chunk retrieved from AVS
%% spec: https://github.com/leo-project/leofs/issues/527#issuecomment-262163109
%% -define(MAX_KEY_SIZE, 2048). already defined at the above section
-define(MAX_MSIZE, 4096).
-define(MAX_CSIZE, ?MAX_DATABLOCK_SIZE).
-define(MAX_OFFSET, 1024 * 1024 * 1024 * 1024 * 16).
-define(MAX_CLOCK, 4633552912011362).


%% @doc Generate an key for backend db
-define(gen_backend_key(_VSN, _AddrId, _Key),
begin
Expand Down
21 changes: 19 additions & 2 deletions src/leo_object_storage_transformer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ transform_metadata(#?METADATA{} = Metadata) ->
transform_metadata(_) ->
{error, invaid_record}.

%% @private
%% check the header
%% according to https://github.com/leo-project/leofs/issues/527#issuecomment-262163109
is_invalid_header(Meta) when Meta#?METADATA.ksize > ?MAX_KEY_SIZE;
Meta#?METADATA.msize > ?MAX_MSIZE;
Meta#?METADATA.csize > ?MAX_DATABLOCK_SIZE;
Meta#?METADATA.offset > ?MAX_OFFSET;
Meta#?METADATA.clock > ?MAX_CLOCK ->
true;
is_invalid_header(_) ->
false.

%% @doc Transport a header-bin to a metadata
-spec(header_bin_to_metadata(HeaderBin) ->
Expand Down Expand Up @@ -348,7 +359,7 @@ header_bin_to_metadata(Bin) ->
end,
case (Timestamp /= 0) of
true ->
#?METADATA{addr_id = AddrId,
Meta = #?METADATA{addr_id = AddrId,
ksize = KSize,
msize = MSize,
dsize = DSize,
Expand All @@ -359,7 +370,13 @@ header_bin_to_metadata(Bin) ->
clock = Clock,
checksum = Checksum,
timestamp = Timestamp,
del = Del};
del = Del},
case is_invalid_header(Meta) of
true ->
{error, {invalid_format, over_limit}};
false ->
Meta
end;
false ->
{error, {invalid_format, unexpected_time_format}}
end
Expand Down

1 comment on commit 0607c70

@yosukehara
Copy link
Member

@yosukehara yosukehara commented on 0607c70 Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mocchira Thanks. I want to improve the error-log message because LeoFS' administrator needs to know full details of an error as below:

  • before:
{error, {invalid_format, over_limit}}
  • after
{error, {invalid_format, [{<ITEM_NAME>, <CAUSE>}, ...] }}

Please sign in to comment.