Skip to content

Commit 399b470

Browse files
authored
Merge pull request #114 from rabbitmq/utf8-filename-fix
Fix potential crash if using UTF8 directory names.
2 parents 5ff6513 + 7aae3f7 commit 399b470

File tree

7 files changed

+54
-48
lines changed

7 files changed

+54
-48
lines changed

src/osiris.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{error, term()} |
9191
{error, term(), config()}.
9292
start_cluster(Config00 = #{name := Name}) ->
93-
?DEBUG("osiris: starting new cluster ~s", [Name]),
93+
?DEBUG("osiris: starting new cluster ~ts", [Name]),
9494
true = osiris_util:validate_base64uri(Name),
9595
%% ensure reference is set
9696
Config0 = maps:merge(#{reference => Name}, Config00),
@@ -254,7 +254,7 @@ start_replicas(Config, [Node | Nodes], ReplicaPids) ->
254254
start_replicas(Config, Nodes, [Pid | ReplicaPids]);
255255
{error, Reason} ->
256256
Name = maps:get(name, Config, undefined),
257-
error_logger:info_msg("osiris:start_replicas for ~s failed to start replica "
257+
error_logger:info_msg("osiris:start_replicas for ~ts failed to start replica "
258258
"on ~w, reason: ~w",
259259
[Name, Node, Reason]),
260260
%% coordinator might try to start this replica in the future

src/osiris_log.erl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ init(#{dir := Dir,
448448
MaxSizeChunks = application:get_env(osiris, max_segment_size_chunks,
449449
?DEFAULT_MAX_SEGMENT_SIZE_C),
450450
Retention = maps:get(retention, Config, []),
451-
?INFO("Stream: ~s will use ~s for osiris log data directory",
451+
?INFO("Stream: ~ts will use ~ts for osiris log data directory",
452452
[Name, Dir]),
453-
?DEBUG("osiris_log:init/1 stream ~s max_segment_size_bytes: ~b,
453+
?DEBUG("osiris_log:init/1 stream ~ts max_segment_size_bytes: ~b,
454454
max_segment_size_chunks ~b, retention ~w",
455455
[Name, MaxSizeBytes, MaxSizeChunks, Retention]),
456456
ok = filelib:ensure_dir(Dir),
@@ -523,7 +523,7 @@ init(#{dir := Dir,
523523
counters:put(Cnt, ?C_SEGMENTS, NumSegments),
524524
osiris_log_shared:set_first_chunk_id(Shared, FstChId),
525525
osiris_log_shared:set_last_chunk_id(Shared, LastChId),
526-
?DEBUG("~s:~s/~b: ~s next offset ~b first offset ~b",
526+
?DEBUG("~s:~s/~b: ~ts next offset ~b first offset ~b",
527527
[?MODULE,
528528
?FUNCTION_NAME,
529529
?FUNCTION_ARITY,
@@ -799,7 +799,7 @@ init_acceptor(Range, EpochOffsets0,
799799

800800
%% then truncate to
801801
IdxFiles = sorted_index_files(Dir),
802-
?DEBUG("~s: ~s ~s from epoch offsets: ~w range ~w",
802+
?DEBUG("~s: ~s ~ts from epoch offsets: ~w range ~w",
803803
[?MODULE, ?FUNCTION_NAME, Name, EpochOffsets, Range]),
804804
RemIdxFiles = truncate_to(Name, Range, EpochOffsets, IdxFiles),
805805
%% after truncation we can do normal init
@@ -835,7 +835,7 @@ chunk_id_index_scan0(Fd, ChunkId) ->
835835

836836
delete_segment_from_index(Index) ->
837837
File = segment_from_index_file(Index),
838-
?DEBUG("osiris_log: deleting segment ~s", [File]),
838+
?DEBUG("osiris_log: deleting segment ~ts", [File]),
839839
ok = prim_file:delete(Index),
840840
ok = prim_file:delete(File),
841841
ok.
@@ -884,7 +884,7 @@ truncate_to(Name, RemoteRange, [{E, ChId} | NextEOs], IdxFiles) ->
884884
%% build_seg_info/1?
885885
end;
886886
{found, #seg_info{file = File, index = IdxFile}} ->
887-
?DEBUG("osiris_log: ~s on node ~s truncating to chunk "
887+
?DEBUG("osiris_log: ~ts on node ~ts truncating to chunk "
888888
"id ~b in epoch ~b",
889889
[Name, node(), ChId, E]),
890890
%% this is the inclusive case
@@ -937,7 +937,7 @@ init_data_reader({StartChunkId, PrevEOT}, #{dir := Dir,
937937
name := Name} = Config) ->
938938
IdxFiles = sorted_index_files(Dir),
939939
Range = offset_range_from_idx_files(IdxFiles),
940-
?DEBUG("osiris_segment:init_data_reader/2 ~s at ~b prev "
940+
?DEBUG("osiris_segment:init_data_reader/2 ~ts at ~b prev "
941941
"~w local range: ~w",
942942
[Name, StartChunkId, PrevEOT, Range]),
943943
%% Invariant: there is always at least one segment left on disk
@@ -1258,7 +1258,7 @@ last_user_chunk_id0([IdxFile | Rest]) ->
12581258
{ok, Id, Pos} ->
12591259
{Id, Pos, IdxFile};
12601260
{error, Reason} ->
1261-
?DEBUG("Could not find user chunk in index file ~s (~p)", [IdxFile, Reason]),
1261+
?DEBUG("Could not find user chunk in index file ~ts (~p)", [IdxFile, Reason]),
12621262
last_user_chunk_id0(Rest)
12631263
end.
12641264

@@ -1564,7 +1564,7 @@ delete_directory(#{name := Name} = Config) when is_map(Config) ->
15641564
delete_directory(Name);
15651565
delete_directory(Name) when ?IS_STRING(Name) ->
15661566
Dir = directory(Name),
1567-
?DEBUG("osiris_log: deleting directory ~s", [Dir]),
1567+
?DEBUG("osiris_log: deleting directory ~ts", [Dir]),
15681568
case file:list_dir(Dir) of
15691569
{ok, Files} ->
15701570
[ok =
@@ -1688,7 +1688,7 @@ first_and_last_seginfos0([FstIdxFile | Rem] = IdxFiles) ->
16881688
{ok, LastSegInfo} ->
16891689
{length(Rem) + 1, FstSegInfo, LastSegInfo};
16901690
{error, Err} ->
1691-
?ERROR("~s: failed to build seg_info from file ~s, error: ~w",
1691+
?ERROR("~s: failed to build seg_info from file ~ts, error: ~w",
16921692
[?MODULE, LastIdxFile, Err]),
16931693
error(Err)
16941694
end;
@@ -1804,7 +1804,7 @@ build_segment_info(SegFile, LastChunkPos, IdxFile) ->
18041804
_Reserved:32>>} ->
18051805
Size = LastChunkPos + LastSize + LastTSize + ?HEADER_SIZE_B,
18061806
{ok, Eof} = file:position(Fd, eof),
1807-
?DEBUG_IF("~s: segment ~s has trailing data ~w ~w",
1807+
?DEBUG_IF("~s: segment ~ts has trailing data ~w ~w",
18081808
[?MODULE, filename:basename(SegFile),
18091809
Size, Eof], Size =/= Eof),
18101810
_ = file:close(Fd),
@@ -1903,7 +1903,7 @@ update_retention(Retention,
19031903
evaluate_retention(Dir, Specs) when is_list(Dir) ->
19041904
% convert to binary for faster operations later
19051905
% mostly in segment_from_index_file/1
1906-
evaluate_retention(list_to_binary(Dir), Specs);
1906+
evaluate_retention(unicode:characters_to_binary(Dir), Specs);
19071907
evaluate_retention(Dir, Specs) when is_binary(Dir) ->
19081908

19091909
{Time, Result} = timer:tc(
@@ -2354,7 +2354,7 @@ open_new_segment(#?MODULE{cfg = #cfg{name = Name,
23542354
_ = close_fd(OldIdxFd),
23552355
Filename = make_file_name(NextOffset, "segment"),
23562356
IdxFilename = make_file_name(NextOffset, "index"),
2357-
?DEBUG("~s: ~s ~s: ~s", [?MODULE, ?FUNCTION_NAME, Name, Filename]),
2357+
?DEBUG("~s: ~s ~ts: ~ts", [?MODULE, ?FUNCTION_NAME, Name, Filename]),
23582358
{ok, IdxFd} =
23592359
file:open(
23602360
filename:join(Dir, IdxFilename), ?FILE_OPTS_WRITE),
@@ -2784,7 +2784,6 @@ close_fd(Fd) ->
27842784

27852785
-ifdef(TEST).
27862786

2787-
% -include_lib("eunit/include/eunit.hrl").
27882787

27892788
part_test() ->
27902789
[<<"ABCD">>] = part(4, [<<"ABCDEF">>]),

src/osiris_replica.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
-include("osiris.hrl").
1313

1414
-define(INFO_(Name, Str, Args),
15-
?INFO("~s [~s:~s/~b] " Str,
15+
?INFO("~ts [~s:~s/~b] " Str,
1616
[Name, ?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY | Args])).
1717

1818
-define(WARN_(Name, Str, Args),
19-
?WARN("~s [~s:~s/~b] " Str,
19+
?WARN("~ts [~s:~s/~b] " Str,
2020
[Name, ?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY | Args])).
2121

2222
-define(ERROR_(Name, Str, Args),
23-
?ERROR("~s [~s:~s/~b] " Str,
23+
?ERROR("~ts [~s:~s/~b] " Str,
2424
[Name, ?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY | Args])).
2525

2626
-define(DEBUG_(Name, Str, Args),
27-
?DEBUG("~s [~s:~s/~b] " Str,
27+
?DEBUG("~ts [~s:~s/~b] " Str,
2828
[Name, ?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY | Args])).
2929
%% osiris replica, starts TCP listener ("server side" of the link),
3030
%% spawns remote reader, TCP listener replicates and
@@ -486,7 +486,7 @@ handle_info({ssl_closed, Socket},
486486
{stop, normal, State};
487487
handle_info({tcp_error, Socket, Error},
488488
#?MODULE{cfg = #cfg{name = Name, socket = Socket}} = State) ->
489-
?DEBUG_(Name, "osiris_replica: ~s Socket error ~p. Exiting...",
489+
?DEBUG_(Name, "osiris_replica: ~ts Socket error ~p. Exiting...",
490490
[Error]),
491491
{stop, {tcp_error, Error}, State};
492492
handle_info({ssl_error, Socket, Error},

src/osiris_replica_reader.erl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ init(#{hosts := Hosts,
152152
connection_token := Token}) ->
153153
process_flag(trap_exit, true),
154154

155-
?DEBUG("~s: trying to connect to replica at ~p", [Name, Hosts]),
155+
?DEBUG("~ts: trying to connect to replica at ~p", [Name, Hosts]),
156156

157157
case maybe_connect(Transport, Hosts, Port, connect_options())
158158
of
159159
{ok, Sock, Host} ->
160-
?DEBUG("~s: successfully connected to host ~p", [Name, Host]),
160+
?DEBUG("~ts: successfully connected to host ~p", [Name, Host]),
161161
CntId = {?MODULE, ExtRef, Host, Port},
162162
CntSpec = {CntId, ?COUNTER_FIELDS},
163163
Config = #{counter_spec => CntSpec, transport => Transport},
@@ -166,7 +166,7 @@ init(#{hosts := Hosts,
166166
{ok, Log} =
167167
osiris_writer:init_data_reader(LeaderPid, TailInfo, Config),
168168
CntRef = osiris_log:counters_ref(Log),
169-
?INFO("~s: starting osiris replica reader at offset ~b",
169+
?INFO("~ts: starting osiris replica reader at offset ~b",
170170
[Name, osiris_log:next_offset(Log)]),
171171

172172
ok = send(Transport, Sock, Token),
@@ -267,31 +267,31 @@ handle_info({'DOWN', Ref, _, _, Info},
267267
leader_monitor_ref = Ref} =
268268
State) ->
269269
%% leader is down, exit
270-
?ERROR("osiris_replica_reader: '~s' detected leader down "
270+
?ERROR("osiris_replica_reader: '~ts' detected leader down "
271271
"with ~W - exiting...",
272272
[Name, Info, 10]),
273273
%% this should be enough to make the replica shut down
274274
ok = close(Transport, Sock),
275275
{stop, Info, State};
276276
handle_info({tcp_closed, Socket},
277277
#state{name = Name, socket = Socket} = State) ->
278-
?DEBUG("osiris_replica_reader: '~s' Socket closed. Exiting...",
278+
?DEBUG("osiris_replica_reader: '~ts' Socket closed. Exiting...",
279279
[Name]),
280280
{stop, normal, State};
281281
handle_info({ssl_closed, Socket},
282282
#state{name = Name, socket = Socket} = State) ->
283-
?DEBUG("osiris_replica_reader: '~s' TLS socket closed. Exiting...",
283+
?DEBUG("osiris_replica_reader: '~ts' TLS socket closed. Exiting...",
284284
[Name]),
285285
{stop, normal, State};
286286
handle_info({tcp_error, Socket, Error},
287287
#state{name = Name, socket = Socket} = State) ->
288-
?DEBUG("osiris_replica_reader: '~s' Socket error ~p. "
288+
?DEBUG("osiris_replica_reader: '~ts' Socket error ~p. "
289289
"Exiting...",
290290
[Name, Error]),
291291
{stop, {tcp_error, Error}, State};
292292
handle_info({ssl_error, Socket, Error},
293293
#state{name = Name, socket = Socket} = State) ->
294-
?DEBUG("osiris_replica_reader: '~s' TLS socket error ~p. "
294+
?DEBUG("osiris_replica_reader: '~ts' TLS socket error ~p. "
295295
"Exiting...",
296296
[Name, Error]),
297297
{stop, {ssl_error, Error}, State};
@@ -301,7 +301,7 @@ handle_info({'EXIT', Ref, Info}, State) ->
301301
[Ref, Info]),
302302
{stop, normal, State};
303303
handle_info(Info, #state{name = Name} = State) ->
304-
?DEBUG("osiris_replica_reader: '~s' unhandled message ~W",
304+
?DEBUG("osiris_replica_reader: '~ts' unhandled message ~W",
305305
[Name, Info, 10]),
306306
{noreply, State}.
307307

src/osiris_util.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ replication_over_tls_configuration(InitArgs, FileConsultFun, LogFun) ->
139139
{error, Error} ->
140140
LogFun(warn,
141141
"Error while reading TLS "
142-
++ "distributon option file ~s: ~p",
142+
++ "distributon option file ~ts: ~p",
143143
[OptFile, Error]),
144144
LogFun(warn,
145145
"Stream replication over TLS will NOT be enabled",
@@ -148,7 +148,7 @@ replication_over_tls_configuration(InitArgs, FileConsultFun, LogFun) ->
148148
R ->
149149
LogFun(warn,
150150
"Unexpected result while reading TLS distributon "
151-
"option file ~s: ~p",
151+
"option file ~ts: ~p",
152152
[OptFile, R]),
153153
LogFun(warn,
154154
"Stream replication over TLS will NOT be enabled",

src/osiris_writer.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ handle_continue(#{name := Name0,
190190
counters:put(CntRef, ?C_COMMITTED_OFFSET, CommittedOffset),
191191
counters:put(CntRef, ?C_EPOCH, Epoch),
192192
EvtFmt = maps:get(event_formatter, Config, undefined),
193-
?INFO("osiris_writer:init/1: name: ~s last offset: ~b "
193+
?INFO("osiris_writer:init/1: name: ~ts last offset: ~b "
194194
"committed chunk id: ~b epoch: ~b",
195195
[Name, LastOffs, CommittedOffset, Epoch]),
196196
Shared = osiris_log:get_shared(Log),
@@ -286,7 +286,7 @@ terminate(Reason,
286286
#?MODULE{log = Log,
287287
data_listeners = Listeners,
288288
cfg = #cfg{name = Name}}) ->
289-
?INFO("osiris_writer:terminate/2: name ~s reason: ~w",
289+
?INFO("osiris_writer:terminate/2: name ~ts reason: ~w",
290290
[Name, Reason]),
291291
_ = ets:delete(osiris_reader_context_cache, self()),
292292
ok = osiris_log:close(Log),

0 commit comments

Comments
 (0)